//select a server to enter private void btn_Server_Click(object sender, RoutedEventArgs e) { int index = lvServerState.SelectedIndex; try { //if server selected is available if (index != -1 && m_DGBiz.CheckServerAvailaility(index)) { String serverName = serverList.Keys.ElementAt(index); String server_URL = serverList.Values.ElementAt(index); //if the player in the server is less than 12 if (m_DGBiz.GetClientInServer(serverName) < 12) { m_DGBiz.AddClientInServer(serverName); m_DGBiz.ChangeUserState(userID, serverName); m_DGBiz.NotifyServer(); enterCharaterSelection(index, server_URL); } else { MessageBox.Show(serverName + " is crowded!"); } } else { MessageBox.Show("The Current Selection is not Available!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
//load window private void Window_Loaded(object sender, RoutedEventArgs e) { DuplexChannelFactory <IDGBizController> DGBiz; NetTcpBinding tcpBinding = new NetTcpBinding(); //release the limitation of the size of message which can be sent tcpBinding.MaxReceivedMessageSize = System.Int32.MaxValue; tcpBinding.ReaderQuotas.MaxArrayLength = System.Int32.MaxValue; string sURL = "net.tcp://localhost:50002/DGBiz"; try { //connect to Biz Tier DGBiz = new DuplexChannelFactory <IDGBizController>(this, tcpBinding, sURL); m_DGBiz = DGBiz.CreateChannel(); } catch (CommunicationObjectFaultedException ex) { MessageBox.Show(ex.Message); } catch (Exception exc) { MessageBox.Show(exc.Message); } //Setup page welcome.Content = "welcome " + username; try { m_DGBiz.RegisterClient(username); serverList = m_DGBiz.GetServerList(); friendIDList = m_DGBiz.GetFriendID(userID); m_DGBiz.ChangeUserState(userID, "online"); m_DGBiz.NotifyServer(); m_DGBiz.NotifyServerState(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }