public void ListenProcedure() { object temp; //object UserList; try { while (true) { temp = formatter.Deserialize(Connectstream); PictureBoxState.Image = ClientList.Images[1];//change icons if (temp is CPacket.LoginPacket) { if (Connected.InvokeRequired) { BeginInvoke(new kdelegate(AddToList), ((CPacket.LoginPacket)temp).user_id, 1); } } //string user = ((CPacket.LoginPacket)temp).user_id; if (temp is CPacket.LogOut) { MessageBox.Show("Server Full"); PictureBoxState.Image = ClientList.Images[0]; Connectstream.Close(); } if (temp is CPacket.LogOutUser) { if (Connected.InvokeRequired) { BeginInvoke(new kdelegate(AddToList), ((CPacket.LogOutUser)temp).UsersDisconnected, 4); } } if (temp is CPacket.UserInSession) { CPacket.UserInSession list = new CPacket.UserInSession(); list = temp as CPacket.UserInSession; if (Connected.InvokeRequired) { BeginInvoke(new kdelegate1(RemovefromToList), list); } } if (temp is CPacket.RequestGame) { CPacket.RequestGame whoasked; whoasked = temp as CPacket.RequestGame; RequestForm requestform = new RequestForm(); if (requestform.ShowDialog() == DialogResult.Yes) { CPacket.AcceptRequestGame RequestAccept = new CPacket.AcceptRequestGame(); RequestAccept.Response = true; RequestAccept.requested_ID = login.user_id; RequestAccept.requester_ID = whoasked.requestedusers; RequestAccept.requester_IP = whoasked.requestedusers_ip; formatter.Serialize(Connectstream, RequestAccept); } else { CPacket.AcceptRequestGame RequestAccept = new CPacket.AcceptRequestGame(); RequestAccept.Response = false; formatter.Serialize(Connectstream, RequestAccept); } } if (temp is CPacket.StartGame) { hosting = new CPacket.StartGame(); hosting = temp as CPacket.StartGame; if (hosting.Which == true) { //HostMode Int32 port = 3006; which = true; //NewPack = new CPacket.GameData(); HostListener = new TcpListener(hosting.Host_IP, port); HostListener.Start(); try { Hostconnection = HostListener.AcceptSocket(); P2PConnectStream = new NetworkStream(Hostconnection);//temporary Networkstream pictureBoxRequestState.Image = ClientList.Images[1]; P2P = new Thread(new ThreadStart(PeerToPeerConnectionHost)); P2P.Start(); //AllThreads[NextLocation] = new Thread(new ParameterizedThreadStart(AreYouTalkingtome)); //AllThreads[NextLocation].Start(AllSockets[NextLocation]); } catch (SocketException e) { MessageBox.Show("No Communication"); } } else { //ClientMode which = false; //MessageBox.Show("Made it to peer to peer start game"); TcpClient Peer2Peer; Peer2Peer = new TcpClient(); try { Peer2Peer.Connect(hosting.Host_IP, 3006); P2PConnectStream = Peer2Peer.GetStream(); if (P2P == null || !P2P.IsAlive) { pictureBoxRequestState.Image = ClientList.Images[1]; P2P = new Thread(new ThreadStart(PeerToPeerConnectionClient)); P2P.Start(); } } catch (SocketException error) { } } } } } catch (Exception e) { MessageBox.Show(" Lost Connection Client"); //PictureBoxState.Image = ClientList.Images[0]; } }
private void NewRequestBtn_Click(object sender, EventArgs e) { requestForm = new RequestForm(db); requestForm.CompletionEvent += OnRequestFormCompletion; requestForm.ShowDialog(); }
public static void RequestForm() { RequestForm requestform = new RequestForm(); requestform.ShowDialog(); }