public void SendCommand(CommandType cmd, int factionId, int mapId, byte[] data, ServerPlayer sourcePlayer = null) { if (sourcePlayer != null && cmd == CommandType.Sync) { int syncId = BitConverter.ToInt32(data, 0); if (!MpVersion.IsDebug && debugOnlySyncCmds.Contains(syncId)) { return; } } byte[] toSave = new ScheduledCommand(cmd, gameTimer, factionId, mapId, data).Serialize(); // todo cull target players if not global mapCmds.GetOrAddNew(mapId).Add(toSave); tmpMapCmds?.GetOrAddNew(mapId).Add(toSave); byte[] toSend = toSave.Append(new byte[] { 0 }); byte[] toSendSource = toSave.Append(new byte[] { 1 }); foreach (var player in PlayingPlayers) { player.conn.Send( Packets.Server_Command, sourcePlayer == player ? toSendSource : toSend ); } }
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 void SendCommand(CommandType cmd, int factionId, int mapId, byte[] data, ServerPlayer sourcePlayer = null) { if (sourcePlayer != null) { bool debugCmd = cmd == CommandType.DebugTools || cmd == CommandType.Sync && debugOnlySyncCmds.Contains(BitConverter.ToInt32(data, 0)); if (!debugMode && debugCmd) { return; } bool hostOnly = cmd == CommandType.Sync && hostOnlySyncCmds.Contains(BitConverter.ToInt32(data, 0)); if (!sourcePlayer.IsHost && hostOnly) { return; } } byte[] toSave = new ScheduledCommand(cmd, gameTimer, factionId, mapId, data).Serialize(); // todo cull target players if not global mapCmds.GetOrAddNew(mapId).Add(toSave); tmpMapCmds?.GetOrAddNew(mapId).Add(toSave); byte[] toSend = toSave.Append(new byte[] { 0 }); byte[] toSendSource = toSave.Append(new byte[] { 1 }); foreach (var player in PlayingPlayers) { player.conn.Send( Packets.Server_Command, sourcePlayer == player ? toSendSource : toSend ); } cmdId++; }