private void buttonRegister_Click(object sender, RoutedEventArgs e) { if (this.textBoxUsername.Text.Length <= 0) { MessageBox.Show("請輸入帳號"); return; } if (this.textBoxPassword.Password.Length <= 0) { MessageBox.Show("請輸入密碼"); return; } if (this.client == null) { this.client = ChatSocket.connect(ChatSetting.serverIp); try { client.newListener(receiveFromServer); } catch (Exception err) { Console.WriteLine(err.ToString()); } } if (this.req_packet == null) { this.req_packet = new Packet(); } this.req_packet.MakePacketRequestUserRegister(this.textBoxUsername.Text, this.textBoxPassword.Password); this.sendToServer(null, this.req_packet); }
public LogInWindow(string serverIp) { InitializeComponent(); gridHome.Visibility = Visibility.Collapsed; stackPanelLogIn.Visibility = Visibility.Visible; this.req_packet = new Packet(); this.client = ChatSocket.connect(serverIp); try { client.newListener(receiveFromServer); } catch (Exception e) { Console.WriteLine(e.ToString()); } }
private bool logIn(string username) { myName = username; if (this.client == null) { this.client = ChatSocket.connect(ChatSetting.serverIp); try { client.newListener(receiveFromServer); } catch (Exception e) { Console.WriteLine(e.ToString()); } } bool connectSuccess; //client = ChatSocket.connect(ChatSetting.serverIp); if (client == null) { connectSuccess = false; } else { connectSuccess = true; } if (connectSuccess) { LoginIn = true; Packet packet = new Packet(); packet.makePacketReportName(username, this.textBoxPassword.Password); sendToServer(null, packet); } return(connectSuccess); }