}//Start Button public void AddToList(object temp) { if (temp is string) { string user = temp as string; UserBox.Items.Add(user); } if (temp is CPacket.LogOutUser) { CPacket.LogOutUser user = new CPacket.LogOutUser(); user = temp as CPacket.LogOutUser; UserBox.Items.Remove(user.UsersDisconnected); } if (temp is CPacket.AcceptRequestGame) { CPacket.AcceptRequestGame list = new CPacket.AcceptRequestGame(); list = temp as CPacket.AcceptRequestGame; CPacket.UserInSession listInSession = new CPacket.UserInSession(); listInSession.user1 = list.requested_ID; listInSession.user2 = list.requester_ID; listInSession.hostIp = list.requester_IP; UserBox.Items.Remove(list.requested_ID); UserBox.Items.Remove(list.requester_ID); //Session[ListNumber].hostIp = list.requester_IP; //Session[ListNumber].HostPlayer = list.requester_ID; UserInSession.Items.Add(list.requester_ID + "-----> " + list.requested_ID); for (int x = 0; x < NextLocation; x++) { //if (AllSockets[x].user_id != list.requested_ID && AllSockets[x].user_id != list.requester_ID) //{ formatter.Serialize(AllSockets[x].ConnStream, listInSession); //} } //ListNumber++; } }
}//Wait for connection public void AreYouTalkingtome(object obj) {//Are You Talking to me LoginData who = null; object temp; CPacket.RequestGame TempPacket; if (obj is LoginData) { who = (LoginData)obj; } //.Items[i].BackColor = Color.Green; try { while (true) { temp = formatter.Deserialize(who.ConnStream); //Waiting for one of the client to takl if (temp is CPacket.RequestGame) //What i'm Getting { try { TempPacket = temp as CPacket.RequestGame; TempPacket.requestedusers = ((CPacket.RequestGame)temp).requestedusers; //MessageBox.Show("Requeste Received"); for (int x = 0; x <= NextLocation; x++) { if (AllSockets[x] != null && TempPacket.requestedusers == AllSockets[x].user_id) { //MessageBox.Show("User Found"); CPacket.RequestGame NewTempPacket = new CPacket.RequestGame(); NewTempPacket.requestedusers = who.user_id; NewTempPacket.requestedusers_ip = who.user_ip; formatter.Serialize(AllSockets[x].ConnStream, NewTempPacket); } } } catch (System.IO.IOException e) { //MessageBox.Show() } //if() //System.IO.IOException } if (temp is CPacket.AcceptRequestGame) { CPacket.AcceptRequestGame ServerRequestAccepted = new CPacket.AcceptRequestGame(); ServerRequestAccepted = temp as CPacket.AcceptRequestGame; if (ServerRequestAccepted.Response == true) { //MessageBox.Show(ServerRequestAccepted.requester_ID + " is asking " + ServerRequestAccepted.requested_ID); CPacket.StartGame StartGame = new CPacket.StartGame(); StartGame.Client_ID = ServerRequestAccepted.requested_ID; StartGame.Host_ID = ServerRequestAccepted.requester_ID; StartGame.Client_IP = ServerRequestAccepted.requested_IP; StartGame.Host_IP = ServerRequestAccepted.requester_IP; // StartGame.session = who.position; //MessageBox.Show(Convert.ToString(StartGame.session)); //Send to Host for (int x = 0; x < NextLocation; x++) { if (AllSockets[x] != null && StartGame.Host_ID == AllSockets[x].user_id) { StartGame.Which = true; //MessageBox.Show(StartGame.Host_ID + " is the Host "); formatter.Serialize(AllSockets[x].ConnStream, StartGame); } } //Send To Client for (int x = 0; x < NextLocation; x++) { if (AllSockets[x] != null && StartGame.Client_ID == AllSockets[x].user_id) { StartGame.Which = false; //MessageBox.Show(StartGame.Client_ID + " is the client "); formatter.Serialize(AllSockets[x].ConnStream, StartGame); } } if (UserBox.InvokeRequired) { BeginInvoke(new kdelegate(AddToList), ServerRequestAccepted); } } if (ServerRequestAccepted.Response == false) { MessageBox.Show(" Don't Create a peer to peer "); } } if (temp is CPacket.LogOut) { try { CPacket.LogOutUser UsersLogedOutList = new CPacket.LogOutUser(); NextLocation--; //UsersLogedOutList = temp as CPacket.LogOutUser; UsersLogedOutList.UsersDisconnected = who.user_id; for (int x = 0; x < NextLocation; x++) { if (AllSockets[x] != null) { formatter.Serialize(AllSockets[x].ConnStream, UsersLogedOutList); } //System.IO.IOException } if (UserBox.InvokeRequired) { BeginInvoke(new kdelegate(AddToList), UsersLogedOutList); } AllSockets[who.position].ConnStream.Close(); AllSockets[who.position].ConnStream = null; AllSockets[who.position] = null; openLocation.Push(who.position); } catch (System.IO.IOException e) { } if (temp is CPacket.WatchingRequest) { CPacket.WatchingRequest SessionRequested = new CPacket.WatchingRequest(); SessionRequested = temp as CPacket.WatchingRequest; } } break; } //WFCThread.Start(); } catch (System.Runtime.Serialization.SerializationException e) { MessageBox.Show("Client is OFF"); } }//Are You Talking to ME