This commit is contained in:
zhbaor 2021-04-24 14:05:23 +08:00
parent 6f3b109c90
commit bf22cb6ae3
2 changed files with 17 additions and 24 deletions

View file

@ -77,8 +77,8 @@ interface Message {
@Component @Component
export default class App extends Vue { export default class App extends Vue {
private nickname = "Zhao Zuohong"; private nickname = "";
private loggedIn = true; private loggedIn = false;
private error = false; private error = false;
private loginInfo = ""; private loginInfo = "";
private message = ""; private message = "";
@ -107,23 +107,12 @@ export default class App extends Vue {
ipcRenderer.send("message", this.message); ipcRenderer.send("message", this.message);
} }
mounted(): void { mounted(): void {
this.messages.push({ ipcRenderer.on("message", (_, nickname, message) => {
avatar: "EE", this.messages.push({
nickname: "EE0000", avatar: this.avatarAbbr(nickname),
message: nickname: nickname,
"The Old Spanish Trail half dollar was a commemorative coin struck by the United States Bureau of the Mint in 1935.", message: message,
}); });
this.messages.push({
avatar: "66",
nickname: "66CCFF",
message:
"It was designed by L. W. Hoffecker, a coin dealer who had been the moving force behind the effort for a Gadsden Purchase half dollar, vetoed by President Herbert Hoover in 1930, and he sought another commemorative coin that he could control if authorizing legislation was passed.",
});
this.messages.push({
avatar: "ZH",
nickname: "Zhao Zuohong",
message:
"He chose the travels of Spanish officer Álvar Núñez Cabeza de Vaca in the early 16th century.",
}); });
} }
} }

View file

@ -89,13 +89,17 @@ ipcMain.on("login", (event, nickname) => {
event.reply("loginStatus", false, "Nickname too short!"); event.reply("loginStatus", false, "Nickname too short!");
} else { } else {
event.reply("loginStatus", true, ""); event.reply("loginStatus", true, "");
client = net.createConnection({ port: 8000 }, () => { client = net.createConnection(
console.log("connected to server."); { host: "cn-zz-bgp-7.sakurafrp.com", port: 8000 },
client.write(`login: ${nickname}\n`); () => {
}); client.write(`login: ${nickname}\n`);
}
);
client.on("data", (data) => { client.on("data", (data) => {
console.log(data.toString()); const msg = data.toString();
const sep = msg.indexOf("\n");
event.reply("message", msg.substring(6, sep), msg.substring(sep + 1));
}); });
} }
}); });