Пример #1
0
    public void HandleConnectionData(HandshakeMessage type, ByteStreamReader stream, IPEndPoint endpoint)
    {
        Console.WriteLine(type);
        if (type == HandshakeMessage.SYN)
        {
            PendingConnectionEntity ce = new PendingConnectionEntity();
            ce.m_connectionId = m_connectionId.Allocate();
            ce.m_sender       = new Connection();
            int port = stream.ReadInt();
            ce.m_pendingStartTime = DateTime.Now;
            ce.m_sender.Connect(new IPEndPoint(endpoint.Address, port));
            m_pending.Add(ce);

            HandshakeStepTwo(ce);
        }
        else if (type == HandshakeMessage.ACK)
        {
            int id = stream.ReadInt();
            PendingConnectionEntity chosen = m_pending.FirstOrDefault(x => x.m_connectionId == id);
            if (chosen != null)
            {
                m_pending.Remove(chosen);
                m_entities[chosen.m_connectionId] = new ConnectionEntity(chosen);
                Network.Server.World.AddPlayer(chosen.m_connectionId);
            }
        }
        else if (type == HandshakeMessage.Disconnect)
        {
            int id = stream.ReadInt();
            Disconnect(id, false);
        }
    }
Пример #2
0
        public static ServerTcpMessage[] Unpack(/*ServerType serverType,*/ byte[] responseData)
        {
            DebugUtils.Assert(responseData != null && responseData.Length > 0, "Response data is null!");

            using (ByteStreamReader reader = new ByteStreamReader(responseData))
            {
                long serverId = reader.ReadLong();
                ClientTcpMessage.sessionId = reader.ReadInt(); //if sessionId is 4 bytes, that's OK.
                int msgNum = reader.ReadByte();
                ServerTcpMessage[] responseMessages = new ServerTcpMessage[msgNum];
                for (int i = 0; i < msgNum; i++)
                {
                    int  len  = reader.ReadShort();
                    int  code = reader.ReadInt();
                    long seq  = reader.ReadLong();

                    if (Enum.IsDefined(typeof(MsgCode), code))
                    {
                        responseMessages[i] = new ServerTcpMessage((MsgCode)code, seq, reader.ReadBytes(len));
                        DebugUtils.Log(DebugUtils.Type.Protocol, "Receive network message, protocol code " + code);
                    }
                    else
                    {
                        DebugUtils.LogError(DebugUtils.Type.Protocol, "For now, the client can't recognize the received protocol code " + code);
                    }
                }

                return(responseMessages);
            }
        }
Пример #3
0
 public override void Deserialize(ByteStreamReader reader)
 {
     base.Deserialize(reader);
     m_who       = reader.ReadInt();
     m_direction = reader.ReadVector2();
     m_point     = reader.ReadVector2();
 }
Пример #4
0
 public override void Deserialize(ByteStreamReader reader)
 {
     m_sessionId       = reader.ReadInt();
     m_actuallySpawned = reader.ReadBool();
     if (m_actuallySpawned)
     {
         m_startPosition = reader.ReadVector2();
     }
 }
Пример #5
0
 public void HandleConnectionData(HandshakeMessage type, ByteStreamReader stream, IPEndPoint endpoint)
 {
     Console.WriteLine(type);
     if (type == HandshakeMessage.SYNACK && State != ConnectionState.Connected)
     {
         int connectionId = stream.ReadInt();
         HandshakeStepThree(connectionId);
     }
 }
Пример #6
0
    public override void Deserialize(ByteStreamReader reader)
    {
        int count = reader.ReadInt();

        for (int i = 0; i < count; i++)
        {
            PlayerState ps = new PlayerState();
            ps.Deserialize(reader);
            states.Add(ps);
        }
        //Network.Log("ID: " + state.id + ", position: " + state.position);
    }
Пример #7
0
    public bool Deserialize(ByteStreamReader reader)
    {
        id = reader.ReadInt();

        int changeMask = reader.ReadByte();

        bool changedPosition = (changeMask & maskOfPositionChange) != 0,
             changedHealth   = (changeMask & maskOfHealthChange) != 0;

        if (changedHealth)
        {
            power = reader.ReadFloat();
            Console.WriteLine("Applying health: " + power);
        }
        if (changedPosition)
        {
            position = reader.ReadVector2();
            Console.WriteLine("Applying position: " + position);
        }

        return(true);
    }
Пример #8
0
 public override void Deserialize(ByteStreamReader reader)
 {
     m_reliableEventId = reader.ReadInt();
 }
Пример #9
0
 public override void Deserialize(ByteStreamReader reader)
 {
     m_direction = reader.ReadVector2();
     m_sessionId = reader.ReadInt();
 }