private void joinGameToolStripMenuItem_Click(object sender, EventArgs e) { var ds = NetworkClasses.GetServerByPlayerId(NetworkClasses.GetPlayer(BoxOFriends.SelectedItems[0].Text).Tables[0].Rows[0]["Player_ID"].ToString()); //Console.WriteLine(ds.Tables[0].Rows[0]["Host"]); Client.Conn = ds.Tables[0].Rows[0]["Host_IP"].ToString(); Client.NetClient.Start(); Client.Connect(); NetworkClasses.JoinServer(Client.Conn, User.PlayerId); //Increments games joined NetworkClasses.UpdateUserValue("User_Stats", "Games_Joined", "Games_Joined+1", User.PlayerId); NetworkClasses.UpdateUserValue("User_List", "Online", "In Lobby", User.PlayerId); Form form = new PlayerLobby(); form.Show(); Dispose(); }
/// <summary> /// Enabled by selecting a server /// On click, joins the selected server and takes the user to the player lobby /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void join_Click(object sender, EventArgs e) { if (!join.Enabled) { return; } var goodConnection = Client.Connect(); if (goodConnection) { NetworkClasses.JoinServer(serverList.SelectedItems[0].SubItems[1].Text, User.PlayerId); NetworkClasses.UpdatePlayerStat(User.PlayerId, "Games_Joined", 1); var lobby = new PlayerLobby(); lobby.Show(); Dispose(); } else { Console.WriteLine("Couldn't Connect"); } }
/// <summary> /// Enabled by selecting a server /// On click, joins the selected server and takes the user to the player lobby /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void join_Click(object sender, EventArgs e) { if (!join.Enabled) { return; } //Checks if user is banned if (NetworkClasses.GetPlayer(User.PlayerId).Tables[0].Rows[0]["IsBanned"].ToString() == "0") { if (Client.Connect()) { try { NetworkClasses.JoinServer(serverList.SelectedItems[0].SubItems[1].Text, User.PlayerId); //Increments games joined NetworkClasses.UpdateUserValue("User_Stats", "Games_Joined", "Games_Joined+1", User.PlayerId); NetworkClasses.UpdateUserValue("User_List", "Online", "In Lobby", User.PlayerId); Form lobby = new PlayerLobby(); lobby.Show(); Dispose(); } catch (Exception exception) { //if invalid, refresh the list (game may no longer exist or be in a joinable state) serverList.Items.Clear(); ListServers(); Console.WriteLine(exception); } } else { Console.WriteLine("Couldn't Connect"); } } else { MessageBox.Show("Can't connect to game, you have been banned. Please contact administrator to lift ban.", "Join Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }