示例#1
0
 private void OnPacketReceived(RailServerPeer peer, IRailClientPacket packet)
 {
     foreach (RailCommandUpdate update in packet.CommandUpdates)
     {
         ProcessCommandUpdate(peer, update);
     }
 }
示例#2
0
        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);
            }
        }
示例#3
0
 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);
     }
 }
示例#4
0
        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);
                    }
                }
            }
        }