private void ProcessCommandUpdate( RailServerPeer peer, RailCommandUpdate update) { RailEntity entity; if (this.Room.TryGet(update.EntityId, out entity)) { if (entity.Controller == peer) { 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); } } } }
private void OnPacketReceived( RailServerPeer peer, IRailClientPacket packet) { foreach (RailCommandUpdate update in packet.CommandUpdates) { this.ProcessCommandUpdate(peer, update); } }
/// <summary> /// Wraps an incoming connection in a peer and stores it. /// </summary> public void AddPeer(IRailNetPeer peer) { if (this.clients.ContainsKey(peer) == false) { RailServerPeer client = new RailServerPeer(peer, this.Interpreter); client.EventReceived += base.OnEventReceived; client.PacketReceived += this.OnPacketReceived; this.clients.Add(peer, client); if (this.ControllerJoined != null) { this.ControllerJoined.Invoke(client); } } }
/// <summary> /// Wraps an incoming connection in a peer and stores it. /// </summary> public void RemovePeer(IRailNetPeer peer) { if (this.clients.ContainsKey(peer)) { RailServerPeer client = this.clients[peer]; this.clients.Remove(peer); if (this.ControllerLeft != null) { this.ControllerLeft.Invoke(client); } // Revoke control of all the entities controlled by that controller client.Shutdown(); } }