public byte[] Serialize() { ByteWriter writer = new ByteWriter(); writer.WriteInt32(blockStart); writer.WriteInt32(blockSize); writer.WriteInt32(mapId); writer.WriteInt32(current); return(writer.GetArray()); }
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()); }
public void OnConnectionRequest(ConnectionRequest req) { if (!arbiter && server.settings.maxPlayers > 0 && server.players.Count(p => !p.IsArbiter) >= server.settings.maxPlayers) { var writer = new ByteWriter(); writer.WriteString("Server is full"); req.Reject(writer.GetArray()); return; } req.Accept(); }
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.GetArray()); }
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.GetArray()); }
public void HandleClientUsername(ByteReader data) { if (connection.username != null && connection.username.Length != 0) { return; } string username = data.ReadString(); if (username.Length < 3 || username.Length > 15) { Player.Disconnect("MpInvalidUsernameLength"); return; } if (!Player.IsArbiter && !UsernamePattern.IsMatch(username)) { Player.Disconnect("MpInvalidUsernameChars"); return; } if (Server.GetPlayer(username) != null) { Player.Disconnect("MpInvalidUsernameAlreadyPlaying"); return; } connection.username = username; Server.SendNotification("MpPlayerConnected", Player.Username); Server.SendChat($"{Player.Username} has joined."); var writer = new ByteWriter(); writer.WriteByte((byte)PlayerListAction.Add); writer.WriteRaw(Player.SerializePlayerInfo()); Server.SendToAll(Packets.Server_PlayerList, writer.GetArray()); }
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); }
public void HandleWorldRequest(ByteReader data) { 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.GetArray(); connection.SendFragmented(Packets.Server_WorldData, packetData); Player.SendPlayerList(); MpLog.Log("World response sent: " + packetData.Length); }