public byte[] Serialize()
        {
            ByteWriter writer = new ByteWriter();

            writer.WriteInt32(blockStart);
            writer.WriteInt32(blockSize);
            writer.WriteInt32(mapId);
            writer.WriteInt32(current);

            return(writer.ToArray());
        }
Ejemplo n.º 2
0
        public byte[] Serialize()
        {
            ByteWriter writer = new ByteWriter();

            writer.WriteInt32(Convert.ToInt32(type));
            writer.WriteInt32(ticks);
            writer.WriteInt32(factionId);
            writer.WriteInt32(mapId);
            writer.WritePrefixedBytes(data);

            return(writer.GetArray());
        }
Ejemplo n.º 3
0
        public static byte[] Serialize(ScheduledCommand cmd)
        {
            ByteWriter writer = new ByteWriter();

            writer.WriteInt32(Convert.ToInt32(cmd.type));
            writer.WriteInt32(cmd.ticks);
            writer.WriteInt32(cmd.factionId);
            writer.WriteInt32(cmd.mapId);
            writer.WriteInt32(cmd.playerId);
            writer.WritePrefixedBytes(cmd.data);

            return(writer.ToArray());
        }
        public byte[] SerializePlayerInfo()
        {
            var writer = new ByteWriter();

            writer.WriteInt32(id);
            writer.WriteString(Username);
            writer.WriteInt32(Latency);
            writer.WriteByte((byte)type);
            writer.WriteByte((byte)status);
            writer.WriteULong(steamId);
            writer.WriteString(steamPersonaName);

            return(writer.ToArray());
        }
Ejemplo n.º 5
0
        public void HandlePing(ByteReader data)
        {
            var writer = new ByteWriter();

            writer.WriteInt32(Player.id);

            writer.WriteInt32(data.ReadInt32()); // Map id
            writer.WriteInt32(data.ReadInt32()); // Planet tile
            writer.WriteFloat(data.ReadFloat()); // X
            writer.WriteFloat(data.ReadFloat()); // Y
            writer.WriteFloat(data.ReadFloat()); // Z

            Server.SendToAll(Packets.Server_PingLocation, writer.ToArray());
        }
Ejemplo n.º 6
0
        private void SendLatencies()
        {
            var writer = new ByteWriter();

            writer.WriteByte((byte)PlayerListAction.Latencies);

            writer.WriteInt32(PlayingPlayers.Count());
            foreach (var player in PlayingPlayers)
            {
                writer.WriteInt32(player.Latency);
                writer.WriteInt32(player.ticksBehind);
            }

            SendToAll(Packets.Server_PlayerList, writer.ToArray());
        }
Ejemplo n.º 7
0
        public byte[] SerializePlayerInfo()
        {
            var writer = new ByteWriter();

            writer.WriteInt32(id);
            writer.WriteString(Username);
            writer.WriteInt32(Latency);
            writer.WriteByte((byte)type);
            writer.WriteByte((byte)status);
            writer.WriteULong(steamId);
            writer.WriteString(steamPersonaName);
            writer.WriteInt32(ticksBehind);
            writer.WriteBool(simulating);
            writer.WriteByte(color.r);
            writer.WriteByte(color.g);
            writer.WriteByte(color.b);

            return(writer.ToArray());
        }
Ejemplo n.º 8
0
        public void HandleSelected(ByteReader data)
        {
            bool reset = data.ReadBool();

            var writer = new ByteWriter();

            writer.WriteInt32(Player.id);
            writer.WriteBool(reset);
            writer.WritePrefixedInts(data.ReadPrefixedInts(200));
            writer.WritePrefixedInts(data.ReadPrefixedInts(200));

            Server.SendToAll(Packets.Server_Selected, writer.ToArray(), excluding: Player);
        }
        public void SendPlayerList()
        {
            var writer = new ByteWriter();

            writer.WriteByte((byte)PlayerListAction.List);
            writer.WriteInt32(Server.PlayingPlayers.Count());

            foreach (var player in Server.PlayingPlayers)
            {
                writer.WriteRaw(player.SerializePlayerInfo());
            }

            conn.Send(Packets.Server_PlayerList, writer.ToArray());
        }
Ejemplo n.º 10
0
        public void HandleCursor(ByteReader data)
        {
            if (Player.lastCursorTick == Server.net.NetTimer)
            {
                return;
            }

            var writer = new ByteWriter();

            byte seq = data.ReadByte();
            byte map = data.ReadByte();

            writer.WriteInt32(Player.id);
            writer.WriteByte(seq);
            writer.WriteByte(map);

            if (map < byte.MaxValue)
            {
                byte  icon = data.ReadByte();
                short x    = data.ReadShort();
                short z    = data.ReadShort();

                writer.WriteByte(icon);
                writer.WriteShort(x);
                writer.WriteShort(z);

                short dragX = data.ReadShort();
                writer.WriteShort(dragX);

                if (dragX != -1)
                {
                    short dragZ = data.ReadShort();
                    writer.WriteShort(dragZ);
                }
            }

            Player.lastCursorTick = Server.net.NetTimer;

            Server.SendToAll(Packets.Server_Cursor, writer.ToArray(), reliable: false, excluding: Player);
        }
Ejemplo n.º 11
0
        public void HandleCursor(ByteReader data)
        {
            var writer = new ByteWriter();

            byte seq = data.ReadByte();
            byte map = data.ReadByte();

            writer.WriteInt32(Player.id);
            writer.WriteByte(seq);
            writer.WriteByte(map);

            if (map < byte.MaxValue)
            {
                byte  icon = data.ReadByte();
                short x    = data.ReadShort();
                short z    = data.ReadShort();

                writer.WriteByte(icon);
                writer.WriteShort(x);
                writer.WriteShort(z);
            }

            Server.SendToAll(Packets.Server_Cursor, writer.GetArray(), reliable: false);
        }
Ejemplo n.º 12
0
        private void SendWorldData()
        {
            int factionId = MultiplayerServer.instance.coopFactionId;

            MultiplayerServer.instance.playerFactions[connection.username] = factionId;

            /*if (!MultiplayerServer.instance.playerFactions.TryGetValue(connection.Username, out int factionId))
             * {
             *  factionId = MultiplayerServer.instance.nextUniqueId++;
             *  MultiplayerServer.instance.playerFactions[connection.Username] = factionId;
             *
             *  byte[] extra = ByteWriter.GetBytes(factionId);
             *  MultiplayerServer.instance.SendCommand(CommandType.SETUP_FACTION, ScheduledCommand.NoFaction, ScheduledCommand.Global, extra);
             * }*/

            if (Server.PlayingPlayers.Count(p => p.FactionId == factionId) == 1)
            {
                byte[] extra = ByteWriter.GetBytes(factionId);
                MultiplayerServer.instance.SendCommand(CommandType.FactionOnline, ScheduledCommand.NoFaction, ScheduledCommand.Global, extra);
            }

            ByteWriter writer = new ByteWriter();

            writer.WriteInt32(factionId);
            writer.WriteInt32(MultiplayerServer.instance.gameTimer);
            writer.WritePrefixedBytes(MultiplayerServer.instance.savedGame);

            writer.WriteInt32(MultiplayerServer.instance.mapCmds.Count);

            foreach (var kv in MultiplayerServer.instance.mapCmds)
            {
                int mapId = kv.Key;

                //MultiplayerServer.instance.SendCommand(CommandType.CreateMapFactionData, ScheduledCommand.NoFaction, mapId, ByteWriter.GetBytes(factionId));

                List <byte[]> mapCmds = kv.Value;

                writer.WriteInt32(mapId);

                writer.WriteInt32(mapCmds.Count);
                foreach (var arr in mapCmds)
                {
                    writer.WritePrefixedBytes(arr);
                }
            }

            writer.WriteInt32(MultiplayerServer.instance.mapData.Count);

            foreach (var kv in MultiplayerServer.instance.mapData)
            {
                int    mapId   = kv.Key;
                byte[] mapData = kv.Value;

                writer.WriteInt32(mapId);
                writer.WritePrefixedBytes(mapData);
            }

            connection.State = ConnectionStateEnum.ServerPlaying;

            byte[] packetData = writer.ToArray();
            connection.SendFragmented(Packets.Server_WorldData, packetData);

            Player.SendPlayerList();

            MpLog.Log("World response sent: " + packetData.Length);
        }
Ejemplo n.º 13
0
 public void WriteLatencyUpdate(ByteWriter writer)
 {
     writer.WriteInt32(Latency);
     writer.WriteInt32(ticksBehind);
     writer.WriteBool(simulating);
 }