protected void ManagePacket(object sender, SocketPacketEventArgs e)
 {
     Debug.Log($"receive {e.Packet.Type}");
     if (e.Packet is PacketGetGameAnswer)
     {
         ManageGetGamesAnswer(e.Packet as PacketGetGameAnswer);
     }
     else if (e.Packet is PacketJoinGameAnswer)
     {
         ManageJoinGameAnswer(e.Packet as PacketJoinGameAnswer);
     }
 }
Exemplo n.º 2
0
        protected override void ManagePacket(object sender, SocketPacketEventArgs e)
        {
            /////////////////////// LOBBY
            if (e.Packet is PacketCreateGameAnswer)
            {
                ManageCreateGameAnswerPacket((PacketCreateGameAnswer)e.Packet);
            }
            else if (e.Packet is PacketGetGameAnswer)
            {
                ManageGetGameAnswerPacket((PacketGetGameAnswer)e.Packet);
            }
            else if (e.Packet is PacketJoinGameAnswer)
            {
                ManageJoinGameAnswerPacket((PacketJoinGameAnswer)e.Packet);
            }
            else if (e.Packet is PacketLeaveGameAnswer)
            {
                ManageLeaveGameAnswerPacket((PacketLeaveGameAnswer)e.Packet);
            }

            /////////////////////// UI
            else if (e.Packet is PacketHandleClickUI)
            {
                ManageHandleUIPacket((PacketHandleClickUI)e.Packet);
            }
            else if (e.Packet is PacketHandleMovementInput)
            {
                ManageHandleMovementRequest((PacketHandleMovementInput)e.Packet);
            }
            else if (e.Packet is PacketHandleSkillInput)
            {
                ManageHandleSkillRequest((PacketHandleSkillInput)e.Packet);
            }

            /////////////////////// LOGIC
            else if (e.Packet is PacketObjectEnter)
            {
                ManageObjectEnter((PacketObjectEnter)e.Packet);
            }
            else if (e.Packet is PacketObjectLeave)
            {
                ManageObjectLeave((PacketObjectLeave)e.Packet);
            }
            else if (e.Packet is PacketHealthUpdate)
            {
                ManageUpdateHealth((PacketHealthUpdate)e.Packet);
            }
            else if (e.Packet is PacketMovementUpdateAnswer)
            {
                ManagePacketMovementAnswer((PacketMovementUpdateAnswer)e.Packet);
            }
        }
Exemplo n.º 3
0
 protected override void ManagePacket(object sender, SocketPacketEventArgs e)
 {
     if (e.Packet is PacketCreateViewObject)
     {
         ManageViewObjectCreation((PacketCreateViewObject)e.Packet);
     }
     else if (e.Packet is PacketUpdateViewObject)
     {
         ManageViewObjectUpdate((PacketUpdateViewObject)e.Packet);
     }
     else if (e.Packet is PacketDeleteViewObject)
     {
         ManageViewObjectDeletion((PacketDeleteViewObject)e.Packet);
     }
 }
Exemplo n.º 4
0
 private void ManagePacket(object sender, SocketPacketEventArgs e)
 {
     Debug.Log($"receive {e.Packet.Type}");
     if (e.Packet is PacketCreateViewObject)
     {
         ManageViewObjectCreation((PacketCreateViewObject)e.Packet);
     }
     else if (e.Packet is PacketUpdateViewObject)
     {
         ManageViewObjectUpdate((PacketUpdateViewObject)e.Packet);
     }
     else if (e.Packet is PacketDeleteViewObject)
     {
         ManageViewObjectDeletion((PacketDeleteViewObject)e.Packet);
     }
 }
Exemplo n.º 5
0
 protected void ManagePacket(object sender, SocketPacketEventArgs e)
 {
     Debug.Log($"receive {e.Packet.Type}");
     if (e.Packet is PacketNewPlayerJoin)
     {
         ManageNewPlayerJoin(e.Packet as PacketNewPlayerJoin);
     }
     if (e.Packet is PacketLeaveGameAnswer)
     {
         ManagePlayerLeave(e.Packet as PacketLeaveGameAnswer);
     }
     if (e.Packet is PacketGameStarted)
     {
         MenuController.ChangeState(MenuController.EGameState.InGame);
     }
 }
Exemplo n.º 6
0
        private void ReceivePingAnswer(object sender, SocketPacketEventArgs e)
        {
            if (TimeHelper.PingPacketSent == TimeHelper.PingPacketRecv &&
                TimeHelper.PingPacketRecv >= Parameters.PING_NUMBER_PACKET)
            {
                if (TimeHelper.PingPacketRecv > 2)
                {
                    // remove max and min
                    TimeHelper.PingPacketNfo = TimeHelper.PingPacketNfo.OrderBy(ts => ts.Value).ToDictionary(ts => ts.Key, ts => ts.Value);
                    uint lastPacketID  = TimeHelper.PingPacketNfo.Keys.Last();
                    uint firstPacketID = TimeHelper.PingPacketNfo.Keys.First();

                    TimeHelper.PingPacketNfo.Remove(lastPacketID);
                    TimeHelper.PingPacketNfo.Remove(firstPacketID);
                }

                // get average
                ulong timestampSum = (ulong)TimeHelper.PingPacketNfo.Sum(ts => ts.Value);
                uint  avgTS        = (uint)timestampSum / (uint)TimeHelper.PingPacketNfo.Count;

                // divide by two because currently we get the time for the packet to go to the server AND comeback
                uint ping = avgTS / 2;
                TimeHelper.CurrentPing = ping;
                Console.WriteLine($"Current Ping : {ping}");

                TimeHelper.PingPacketNfo.Clear();

                // Now sync clock with the server's one
                PacketSyncClockRequest packetSync = new PacketSyncClockRequest();
                m_udpConnection.SendPacket(packetSync);
            }
            else
            {
                // If there isn't enough ping info to estimate current ping, send another ping request
                PacketPingRequest ping = new PacketPingRequest();
                TimeHelper.PingPacketNfo.Add(ping.Id, 0);
                m_udpConnection.SendPacket(ping);
            }
        }
Exemplo n.º 7
0
        private void InitUdp(object sender, SocketPacketEventArgs e)
        {
            IPAddress addr;

            if (IPAddress.TryParse((e.Packet as PacketClientConnected).AddrUdp, out addr))
            {
                Console.WriteLine("UDP addr : " + addr.ToString() + " | port : " + (e.Packet as PacketClientConnected).PortUdp);
                m_udpConnection = new DeusUdpConnection(new IPEndPoint(addr, (int)(e.Packet as PacketClientConnected).PortUdp));

                PacketConnectedUdpAnswer feedback = new PacketConnectedUdpAnswer(m_playerName);
                m_udpConnection.SendPacket(feedback);


                PacketPingRequest ping = new PacketPingRequest();
                TimeHelper.PingPacketNfo.Add(ping.Id, 0);
                m_udpConnection.SendPacket(ping);
            }
            else
            {
                throw new Exception("Cannot parse IPAdress, abort the UDP connection...");
            }
        }
Exemplo n.º 8
0
 public void ManagePacket(object sender, SocketPacketEventArgs e)
 {
     Console.WriteLine(e.Packet.Type);
 }
Exemplo n.º 9
0
 protected abstract void ManagePacket(object sender, SocketPacketEventArgs e);
Exemplo n.º 10
0
 private void SendUdpMessage(object sender, SocketPacketEventArgs e)
 {
     //Console.WriteLine($"Send UDP {e.Packet.Type}");
     SendPacket(e.Packet, false);
 }
Exemplo n.º 11
0
 private void ReceiveSyncClockAnswer(object sender, SocketPacketEventArgs e)
 {
     TimeHelper.Sync(e.Packet.RecvTimeStamp, (e.Packet as PacketSyncClockAnswer).DistantClockValue);
 }
Exemplo n.º 12
0
 private void OnConnected(object sender, SocketPacketEventArgs e)
 {
     Debug.Log("Connected !");
     MenuController.ChangeState(MenuController.EGameState.Menu);
 }