diff --git a/src/App.vue b/src/App.vue index fd29db4..1740736 100755 --- a/src/App.vue +++ b/src/App.vue @@ -77,8 +77,8 @@ interface Message { @Component export default class App extends Vue { - private nickname = "Zhao Zuohong"; - private loggedIn = true; + private nickname = ""; + private loggedIn = false; private error = false; private loginInfo = ""; private message = ""; @@ -107,23 +107,12 @@ export default class App extends Vue { ipcRenderer.send("message", this.message); } mounted(): void { - this.messages.push({ - avatar: "EE", - nickname: "EE0000", - message: - "The Old Spanish Trail half dollar was a commemorative coin struck by the United States Bureau of the Mint in 1935.", - }); - 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.", + ipcRenderer.on("message", (_, nickname, message) => { + this.messages.push({ + avatar: this.avatarAbbr(nickname), + nickname: nickname, + message: message, + }); }); } } diff --git a/src/background.ts b/src/background.ts index cd5ca00..e64041c 100755 --- a/src/background.ts +++ b/src/background.ts @@ -89,13 +89,17 @@ ipcMain.on("login", (event, nickname) => { event.reply("loginStatus", false, "Nickname too short!"); } else { event.reply("loginStatus", true, ""); - client = net.createConnection({ port: 8000 }, () => { - console.log("connected to server."); - client.write(`login: ${nickname}\n`); - }); + client = net.createConnection( + { host: "cn-zz-bgp-7.sakurafrp.com", port: 8000 }, + () => { + client.write(`login: ${nickname}\n`); + } + ); 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)); }); } });