private void OnPacketReceived(RailServerPeer peer, IRailClientPacket packet) { foreach (RailCommandUpdate update in packet.CommandUpdates) { ProcessCommandUpdate(peer, update); } }
public void RemoveClient(IRailNetPeer netClient) { if (clients.ContainsKey(netClient)) { RailServerPeer client = clients[netClient]; clients.Remove(netClient); Room.RemoveClient(client); // Revoke control of all the entities controlled by that client client.Shutdown(); ClientRemoved?.Invoke(client); } }
public void AddClient(IRailNetPeer netPeer, string identifier) { if (clients.ContainsKey(netPeer) == false) { RailServerPeer client = new RailServerPeer(Resource, netPeer, Interpreter) { Identifier = identifier }; client.EventReceived += OnEventReceived; client.PacketReceived += OnPacketReceived; clients.Add(netPeer, client); Room.AddClient(client); ClientAdded?.Invoke(client); } }
private void ProcessCommandUpdate(RailServerPeer peer, RailCommandUpdate update) { if (Room.TryGet(update.EntityId, out RailEntityServer entity)) { bool canReceive = entity.Controller == peer && entity.IsRemoving == false; if (canReceive) { foreach (RailCommand command in update.Commands) { entity.ReceiveCommand(command); } } else // Can't send commands to that entity, so dump them { foreach (RailCommand command in update.Commands) { RailPool.Free(command); } } } }