Ejemplo n.º 1
0
 public void PositionUpdate(NetPlayer player, Vector3 position, Quaternion orientation)
 {
     actions.Enqueue(() =>
     {
         Players[player].Transform = Matrix4.CreateFromQuaternion(orientation) * Matrix4.CreateTranslation(position);
     });
 }
Ejemplo n.º 2
0
        public void Despawn(NetPlayer player)
        {
            var m = server.NetServer.CreateMessage();

            m.Write(new DespawnObjectPacket()
            {
                ID = player.ID
            });
        }
Ejemplo n.º 3
0
 public void RemovePlayer(NetPlayer player)
 {
     actions.Enqueue(() =>
     {
         GameWorld.Objects.Remove(Players[player]);
         Players.Remove(player);
         foreach (var p in Players)
         {
             p.Key.Despawn(player);
         }
     });
 }
Ejemplo n.º 4
0
        public void SpawnPlayer(NetPlayer p)
        {
            var m = server.NetServer.CreateMessage();

            m.Write(new SpawnObjectPacket()
            {
                ID          = p.ID,
                Name        = p.Name,
                Position    = p.Position,
                Orientation = p.Orientation,
                Loadout     = p.Character.EncodeLoadout()
            });
            server.NetServer.SendMessage(m, connection, NetDeliveryMethod.ReliableOrdered);
        }
Ejemplo n.º 5
0
 public void SpawnPlayer(NetPlayer player, Vector3 position, Quaternion orientation)
 {
     actions.Enqueue(() =>
     {
         foreach (var p in Players)
         {
             player.SpawnPlayer(p.Key);
             p.Key.SpawnPlayer(player);
         }
         var obj = new GameObject()
         {
             World = GameWorld
         };
         GameWorld.Objects.Add(obj);
         Players[player]           = obj;
         Players[player].Transform = Matrix4.CreateFromQuaternion(orientation) * Matrix4.CreateTranslation(position);
     });
 }
Ejemplo n.º 6
0
        void NetThread()
        {
            FLLog.Info("Server", "Loading Game Data...");
            GameData.LoadData();
            FLLog.Info("Server", "Finished Loading Game Data");
            Database = new ServerDatabase(DbConnectionString);
            var netconf = new NetPeerConfiguration(AppIdentifier);

            netconf.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
            netconf.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
            netconf.EnableMessageType(NetIncomingMessageType.UnconnectedData);
            netconf.Port = Port;
            netconf.MaximumConnections = 200;
            NetServer = new NetServer(netconf);
            NetServer.Start();
            FLLog.Info("Server", "Listening on port " + Port);
            NetIncomingMessage im;

            while (running)
            {
                while ((im = NetServer.ReadMessage()) != null)
                {
                    switch (im.MessageType)
                    {
                    case NetIncomingMessageType.DebugMessage:
                    case NetIncomingMessageType.ErrorMessage:
                    case NetIncomingMessageType.WarningMessage:
                    case NetIncomingMessageType.VerboseDebugMessage:
                        FLLog.Info("Lidgren", im.ReadString());
                        NetServer.Recycle(im);
                        break;

                    case NetIncomingMessageType.ConnectionApproval:
                        //Ban IP?
                        im.SenderConnection.Approve();
                        NetServer.Recycle(im);
                        break;

                    case NetIncomingMessageType.DiscoveryRequest:
                        NetOutgoingMessage dresp = NetServer.CreateMessage();
                        //Include Server Data
                        dresp.Write(ServerName);
                        dresp.Write(ServerDescription);
                        dresp.Write(GameData.DataVersion);
                        dresp.Write(NetServer.ConnectionsCount);
                        dresp.Write(NetServer.Configuration.MaximumConnections);
                        //Send off
                        NetServer.SendDiscoveryResponse(dresp, im.SenderEndPoint);
                        NetServer.Recycle(im);
                        break;

                    case NetIncomingMessageType.UnconnectedData:
                        //Respond to pings
                        try
                        {
                            if (im.ReadUInt32() == NetConstants.PING_MAGIC)
                            {
                                var om = NetServer.CreateMessage();
                                om.Write(NetConstants.PING_MAGIC);
                                NetServer.SendUnconnectedMessage(om, im.SenderEndPoint);
                            }
                        }
                        catch (Exception)
                        {
                        }
                        break;

                    case NetIncomingMessageType.StatusChanged:
                        NetConnectionStatus status = (NetConnectionStatus)im.ReadByte();

                        string reason = im.ReadString();
                        FLLog.Info("Lidgren", NetUtility.ToHexString(im.SenderConnection.RemoteUniqueIdentifier) + " " + status + ": " + reason);

                        if (status == NetConnectionStatus.Connected)
                        {
                            FLLog.Info("Lidgren", "Remote hail: " + im.SenderConnection.RemoteHailMessage.ReadString());
                            BeginAuthentication(NetServer, im.SenderConnection);
                        }
                        else if (status == NetConnectionStatus.Disconnected)
                        {
                            FLLog.Info("Lidgren", im.SenderEndPoint.ToString() + " disconnected");
                            if (im.SenderConnection.Tag is NetPlayer)
                            {
                                ((NetPlayer)im.SenderConnection.Tag).Disconnected();
                            }
                        }
                        NetServer.Recycle(im);
                        break;

                    case NetIncomingMessageType.Data:
                        var pkt = im.ReadPacket();
                        if (im.SenderConnection.Tag == TagConnecting)
                        {
                            if (pkt is AuthenticationReplyPacket)
                            {
                                var auth = (AuthenticationReplyPacket)pkt;

                                //im.SenderConnection.Disconnect("boilerplate reason from server");

                                /*
                                 *                                  var authkind = (AuthenticationKind)im.ReadByte();
                                 *                                  var guid = new Guid(im.ReadBytes(16));
                                 *                                  if (guid == Guid.Empty) im.SenderConnection.Disconnect("Invalid UUID");
                                 *                                  FLLog.Info("Lidgren", "GUID for " + im.SenderEndPoint + " = " + guid.ToString());
                                 *                                  var p = new NetPlayer(im.SenderConnection, this, guid);
                                 *                                  im.SenderConnection.Tag = p;
                                 *                                  AsyncManager.RunTask(() => p.DoAuthSuccess());*/

                                var p = new NetPlayer(im.SenderConnection, this, auth.Guid);
                                im.SenderConnection.Tag = p;
                                AsyncManager.RunTask(() => p.DoAuthSuccess());
                            }
                            else
                            {
                                im.SenderConnection.Disconnect("Invalid Packet");
                            }
                            NetServer.Recycle(im);
                        }
                        else
                        {
                            var player = (NetPlayer)im.SenderConnection.Tag;
                            AsyncManager.RunTask(() => player.ProcessPacket(pkt));
                            NetServer.Recycle(im);
                        }
                        break;
                    }
                }
                Thread.Sleep(0);                 //Reduce CPU load
            }
            NetServer.Shutdown("Shutdown");
            Database.Dispose();
        }
Ejemplo n.º 7
0
        void NetThread()
        {
            FLLog.Info("Server", "Loading Game Data...");
            GameData.LoadData();
            FLLog.Info("Server", "Finished Loading Game Data");
            Database = new ServerDatabase(DbConnectionString, GameData);
            var netconf = new NetPeerConfiguration(AppIdentifier);

            netconf.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
            netconf.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
            netconf.Port = Port;
            netconf.MaximumConnections = 200;
            NetServer = new NetServer(netconf);
            NetServer.Start();
            FLLog.Info("Server", "Listening on port " + Port);
            NetIncomingMessage im;

            while (running)
            {
                while ((im = NetServer.ReadMessage()) != null)
                {
                    switch (im.MessageType)
                    {
                    case NetIncomingMessageType.DebugMessage:
                    case NetIncomingMessageType.ErrorMessage:
                    case NetIncomingMessageType.WarningMessage:
                    case NetIncomingMessageType.VerboseDebugMessage:
                        FLLog.Info("Lidgren", im.ReadString());
                        NetServer.Recycle(im);
                        break;

                    case NetIncomingMessageType.ConnectionApproval:
                        //Ban IP?
                        im.SenderConnection.Approve();
                        NetServer.Recycle(im);
                        break;

                    case NetIncomingMessageType.DiscoveryRequest:
                        NetOutgoingMessage dresp = NetServer.CreateMessage();
                        //Include Server Data
                        dresp.Write(ServerName);
                        dresp.Write(ServerDescription);
                        dresp.Write(NetServer.ConnectionsCount);
                        dresp.Write(NetServer.Configuration.MaximumConnections);
                        //Send off
                        NetServer.SendDiscoveryResponse(dresp, im.SenderEndPoint);
                        NetServer.Recycle(im);
                        break;

                    case NetIncomingMessageType.StatusChanged:
                        NetConnectionStatus status = (NetConnectionStatus)im.ReadByte();

                        string reason = im.ReadString();
                        FLLog.Info("Lidgren", NetUtility.ToHexString(im.SenderConnection.RemoteUniqueIdentifier) + " " + status + ": " + reason);

                        if (status == NetConnectionStatus.Connected)
                        {
                            FLLog.Info("Lidgren", "Remote hail: " + im.SenderConnection.RemoteHailMessage.ReadString());
                            BeginAuthentication(NetServer, im.SenderConnection);
                        }
                        NetServer.Recycle(im);
                        break;

                    case NetIncomingMessageType.Data:
                        var kind = (PacketKind)im.ReadByte();
                        if (im.SenderConnection.Tag == TagConnecting)
                        {
                            if (kind == PacketKind.Authentication)
                            {
                                var authkind = (AuthenticationKind)im.ReadByte();
                                var guid     = new Guid(im.ReadBytes(16));
                                if (guid == Guid.Empty)
                                {
                                    im.SenderConnection.Disconnect("Invalid UUID");
                                }
                                FLLog.Info("Lidgren", "GUID for " + im.SenderEndPoint + " = " + guid.ToString());
                                var p = new NetPlayer(im.SenderConnection, this, guid);
                                im.SenderConnection.Tag = p;
                                AsyncManager.RunTask(() => p.DoAuthSuccess());
                            }
                            else
                            {
                                im.SenderConnection.Disconnect("Invalid Packet");
                            }
                        }
                        else
                        {
                            var player = (NetPlayer)im.SenderConnection.Tag;
                            AsyncManager.RunTask(() => player.ProcessPacket(im, kind));
                        }
                        break;
                    }
                }
                Thread.Sleep(1);                 //Reduce CPU load
            }
            Database.Dispose();
        }