private void Reception() { int TryCount = 0; while (true) { do { Exit(); TryCount++; Thread.Sleep(250); Send(TramePreGen.AskNumberOfPlayer); Thread.Sleep(50); do { m_Receiver = ConnectionUDP.Receiver(); switch (m_Receiver[0]) { case (byte)PacketUse.AskNumberOfPlayer: if (m_ID != 0) { Send(TramePreGen.AnswerListeJoueur(m_PlayerCount, m_ID)); } break; case (byte)PacketUse.AnswerNumberOfPlayer: Enter(); if (m_Receiver[2] > m_PlayerCount || m_ID == 0) { //this may reset the last player for (; m_PlayerCount < m_Receiver[2]; m_PlayerCount++) { m_PlayerList[m_PlayerCount] = new PlayerData(m_PlayerCount, TickCounter.ElapsedTicks); m_PlayerTime[m_PlayerCount] = Environment.TickCount; } if (m_ID == 0) { m_ID = m_Receiver[2]; m_ID++; m_PlayerCount++; m_PlayerList[m_ID] = new PlayerData(m_ID, TickCounter.ElapsedTicks); m_PlayerTime[m_ID] = Environment.TickCount; Send(TramePreGen.AnswerListeJoueur(m_PlayerCount, m_ID)); Send(TramePreGen.AskAutoVerif(ID)); } } Exit(); break; case (byte)PacketUse.InfoJoueur: m_PlayerList[m_Receiver[1]] = TramePreGen.ReceiverInfoJoueur(m_Receiver); m_PlayerTime[m_Receiver[1]] = Environment.TickCount; break; case (byte)PacketUse.ResetAllID: if (m_Receiver[1] == m_ID) { m_ID = 1; m_PlayerCount = 1; Thread.Sleep(RNG.Next(0, 50)); //GenMap(); } else { m_ID = 0; m_PlayerCount = 0; Send(TramePreGen.AskNumberOfPlayer); } break; case (byte)PacketUse.Ping: if (m_Receiver[2] == m_ID) { m_Receiver[1] ^= m_Receiver[2] ^= m_Receiver[1] ^= m_Receiver[2]; //swap 1 w/ 2 } m_Receiver[0] = (byte)PacketUse.Pong; Send(m_Receiver); break; case (byte)PacketUse.AskAutoVerif: if (m_Receiver[1] == m_ID) { AutoVerifData = RNG.Next(1, int.MaxValue); Send(TramePreGen.AnswerAutoVerif(AutoVerifData, m_ID)); } break; case (byte)PacketUse.AnswerAutoVerif: if (m_Receiver[1] == m_ID) { if (AutoVerifData < BitConverter.ToInt32(m_Receiver, 2)) { m_ID = 0; m_PlayerCount = 0; Send(TramePreGen.AskNumberOfPlayer); } } break; default: break; }//Switch if (LastTickCheck + 5000 < Environment.TickCount) { LastTickCheck = Environment.TickCount + RNG.Next(1, 500); Send(TramePreGen.AskAutoVerif(m_ID)); } } while (m_ID != 0);//While(true) Enter(); } while (TryCount < 10 && m_ID == 0); if (TryCount == 10 && m_ID == 0) { //GenMap(); m_ID = 1; m_PlayerCount = 1; //Send(TramePreGen.AnswerMap) } TryCount = 0; Thread.Sleep(300); Send(TramePreGen.AskAutoVerif(ID)); } }
private void Main_MouseDown(object sender, MouseEventArgs e) { GP.PlayerList[GP.ID].Position = this.PointToClient(Cursor.Position); GP.Send(TramePreGen.InfoJoueur(GP.PlayerList[GP.ID], GP.ID, GP.PacketID)); }