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); } }
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); } }
public override void Deserialize(ByteStreamReader reader) { base.Deserialize(reader); m_who = reader.ReadInt(); m_direction = reader.ReadVector2(); m_point = reader.ReadVector2(); }
public override void Deserialize(ByteStreamReader reader) { m_sessionId = reader.ReadInt(); m_actuallySpawned = reader.ReadBool(); if (m_actuallySpawned) { m_startPosition = reader.ReadVector2(); } }
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); } }
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); }
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); }
public override void Deserialize(ByteStreamReader reader) { m_reliableEventId = reader.ReadInt(); }
public override void Deserialize(ByteStreamReader reader) { m_direction = reader.ReadVector2(); m_sessionId = reader.ReadInt(); }