Ejemplo n.º 1
0
        public static void ReadMessage(byte[] message, int clientID)
        {
            Envelope envelope = SerializationHandler.Deserialize <Envelope>(message);

            if (envelope == null)
            {
                throw new NotAnEnvelopeException();
            }
            switch (envelope.PacketType)
            {
            case Packets.None:
                Debug.Log("None");
                break;

            case Packets.String:
                string value = SerializationHandler.Deserialize <string>(envelope.Packet);
                if (value == null)
                {
                    throw new WrongPacketTypeException();
                }
                Debug.Log(value);
                break;

            case Packets.Login:
                HandleLogin(SerializationHandler.Deserialize <Login>(envelope.Packet), clientID);
                break;

            case Packets.JoinTeam:
                HandleJoinTeam(SerializationHandler.Deserialize <JoinTeam>(envelope.Packet));
                break;

            case Packets.PlayerUpdate:
                HandlePlayerUpdate(SerializationHandler.Deserialize <PlayerUpdate>(envelope.Packet));
                break;

            case Packets.SpawnSnowball:
                HandleSpawnSnowball(SerializationHandler.Deserialize <SpawnSnowball>(envelope.Packet));
                break;

            case Packets.SetSkin:
                HandleSetSkin(SerializationHandler.Deserialize <SetSkin>(envelope.Packet));
                break;

            case Packets.RequestLeaderboardData:
                HandleRequestLeaderboardData(SerializationHandler.Deserialize <RequestLeaderboardData>(envelope.Packet));
                break;

            case Packets.TestConnection:
                HandleTestConnection(clientID);
                break;

            default:
                break;
            }
        }
Ejemplo n.º 2
0
        public void SendPacket <T>(T packet, Packets packetType) where T : class
        {
            if (!Connected)
            {
                return;
            }
            Envelope envelope = new Envelope
            {
                PacketType = packetType,
                Packet     = SerializationHandler.Serialize(packet, _bufferSize - 512)
            };
            byte error;

            byte[] message = SerializationHandler.Serialize(envelope, _bufferSize);
            NetworkTransport.Send(_socketID, ClientID, _channelID, message, _bufferSize, out error);
        }
Ejemplo n.º 3
0
        public void SendPacket <T>(T packet, Packets packetType, int clientID) where T : class
        {
            if (!ConnectionManager.Instance.GetClientConnected(clientID))
            {
                return;
            }
            Envelope envelope = new Envelope
            {
                PacketType = packetType,
                Packet     = SerializationHandler.Serialize(packet, _bufferSize - 512)
            };
            byte error;

            byte[] message  = SerializationHandler.Serialize(envelope, _bufferSize);
            int    socketID = _ports[ConnectionManager.Instance.GetClientPort(clientID)];

//            Thread.Sleep(200);
            NetworkTransport.Send(socketID, clientID, _channelID, message, _bufferSize, out error);
        }
Ejemplo n.º 4
0
        public static void ReadMessage(byte[] message)
        {
            Envelope envelope = SerializationHandler.Deserialize <Envelope>(message);

            if (envelope == null)
            {
                throw new NotAnEnvelopeException();
            }
            switch (envelope.PacketType)
            {
            case Packets.None:
                Debug.Log("None");
                break;

            case Packets.String:
                string stringVal = SerializationHandler.Deserialize <string>(envelope.Packet);
                Debug.Log(stringVal);
                break;

            case Packets.AckLogin:
                AckLogin ackLogin = SerializationHandler.Deserialize <AckLogin>(envelope.Packet);
                HandleAckLogin(ackLogin);
                break;

            case Packets.AckJoinTeam:
                AckJoinTeam ackJoinTeam = SerializationHandler.Deserialize <AckJoinTeam>(envelope.Packet);
                HandleAckJoinTeam(ackJoinTeam);
                break;

            case Packets.DestroyObject:
                DestroyObject destroyObject = SerializationHandler.Deserialize <DestroyObject>(envelope.Packet);
                HandleDestroyObject(destroyObject);
                break;

            case Packets.PlayerSync:
                PlayerSync playerSync = SerializationHandler.Deserialize <PlayerSync>(envelope.Packet);
                HandlePlayerSync(playerSync);
                break;

            case Packets.SnowballSync:
                SnowballSync snowballSync = SerializationHandler.Deserialize <SnowballSync>(envelope.Packet);
                HandleSnowballSync(snowballSync);
                break;

            case Packets.SnowPileSync:
                SnowPileSync snowPileSync = SerializationHandler.Deserialize <SnowPileSync>(envelope.Packet);
                HandleSnowPileSync(snowPileSync);
                break;

            case Packets.LeaderboardData:
                LeaderboardDataEntry leaderboardDataResponse = SerializationHandler.Deserialize <LeaderboardDataEntry>(envelope.Packet);
                HandleLeaderboardDataEntry(leaderboardDataResponse);
                break;

            case Packets.EndLeaderboardResponse:
                HandleEndLeaderboardResponse();
                break;

            case Packets.AckConnection:
                HandleAckConnection();
                break;

            default:
                break;
            }
        }