Esempio n. 1
0
 public static void SaveAllToSQL()
 {
     foreach (NetConnection Connection in ServerNetworkSceneComponent.GetNetServer().Connections)
     {
         LoginManagerServer user = MapContainer.GetLoginByID(Connection.RemoteUniqueIdentifier);
         if (user != null && user.GetCharacter() != null)
         {
             UpdateToSQL(user.username, user.GetCharacter().CreateJsonFromCharacter());
         }
     }
 }
Esempio n. 2
0
        public void AssignToLayer(Scene scene, LoginManagerServer login, PlayerComponent pc = null)
        {
            MapLayer assignedLayer = null;

            if (MapType == MapType.Multi)
            {
                //find first that isn't full
                assignedLayer = MapLayers.Find(l =>
                {
                    if (l != null)
                    {
                        return(l.LayerLogins.Count < ConstantValues.MaxConnectionsToLayer);
                    }
                    return(false);
                });
                //if none found then make new layer
                if (assignedLayer == null)
                {
                    assignedLayer = CreateNewLayer(-1);
                }
                login.GetCharacter().LastMultiLocation = MapName;
            }
            else if (MapType == MapType.Single)
            {
                assignedLayer = CreateNewLayer(login.GetUniqueID());
            }

            assignedLayer.AddLoginToLayer(login);

            Entity e = Core.Scene.FindEntity(login.GetCharacter()._name);

            if (e == null)
            {
                FSRigidBody fbody = new FSRigidBody().SetBodyType(BodyType.Dynamic).SetIgnoreGravity(true).SetLinearDamping(15f);

                e = scene.CreateEntity(login.GetCharacter()._name).SetPosition(login.GetCharacter().physicalPosition);
                e.AddComponent(fbody)
                .AddComponent(new FSCollisionCircle(25))
                .AddComponent(new PlayerComponent(login)
                {
                    CurrentLayer = assignedLayer
                })
                .AddComponent(new Mover())
                .AddComponent(new CircleCollider(25))
                .AddComponent(new StatsComponent())
                .AddComponent(new DamageComponent());
                fbody.Body.FixedRotation = true;
                login.SetEntity(e);
            }
            if (pc != null)
            {
                pc.CurrentLayer = assignedLayer;
            }
        }
Esempio n. 3
0
        public void Update()
        {
            //checks if client is still connected
            //CheckIfConnected();
            timeSpan += Time.DeltaTime;
            //Updates every 1/20 second
            if (timeSpan > 0.05)
            {
                if (CurrentLayer != null)
                {
                    HashSet <LoginManagerServer> characterlist = CurrentLayer.LayerLogins;

                    if (characterlist != null && characterlist.Count > 0 && loginManager != null)
                    {
                        CharacterPlayer tempc = loginManager.GetCharacter();

                        //sets the position of the entity's physical body as the physical position
                        FSRigidBody v = Core.Scene.FindEntity(tempc._name).GetComponent <FSRigidBody>();

                        tempc.physicalPosition = v.Transform.Position;

                        DataTemplate dataTemplate = new DataTemplate
                        {
                            RecieverCharacter = tempc,
                            OthersCharacters  = FillRecieverList(characterlist, tempc)
                        };
                        //makes the position relative to client's side of the map position
                        dataTemplate.RecieverCharacter.physicalPosition = dataTemplate.RecieverCharacter.physicalPosition - MapContainer.GetMapByName(CurrentLayer.MapName).Entity.Position;
                        string posString = Newtonsoft.Json.JsonConvert.SerializeObject(dataTemplate);

                        MessageManager.SendStringToUniqueID(Entity.Scene, posString, loginManager.GetUniqueID(), MessageType.GameUpdate);
                    }
                }
            }
        }
Esempio n. 4
0
        public static void DisconnectConnection(NetConnection sender, Scene scene)
        {
            NetServer server = ServerNetworkSceneComponent.GetNetServer();

            LoginManagerServer login = MapContainer.GetLoginByID(sender.RemoteUniqueIdentifier);

            if (login != null)
            {
                CharacterPlayer characterPlayer = login.GetCharacter();

                //Saves data to SQL database
                string characterString = Newtonsoft.Json.JsonConvert.SerializeObject(characterPlayer, new StringEnumConverter());
                SQLManager.UpdateToSQL(login.username, characterString);

                //removes login manager
                MapContainer.RemoveLoginByID(login.GetUniqueID());

                if (characterPlayer != null)
                {
                    //removes entity
                    CharacterManager.RemoveCharacterFromScene(scene, characterPlayer._name);
                }
            }

            //removes the connection
            sender.Disconnect("Closed");
            Console.WriteLine("Disconnected! Connected: " + ServerNetworkSceneComponent.GetNetServer().ConnectionsCount);
            MainScene.ConnectedCount.SetText("Current connections: " + server.ConnectionsCount);
        }
Esempio n. 5
0
        //for logging in
        public static void AssignLogin(Scene scene, LoginManagerServer login)
        {
            string map = login.GetCharacter().LastMultiLocation;
            Map    foundMap;

            if (map != null)
            {
                foundMap = GetMapByName(map);

                login.GetCharacter().MoveToPos(foundMap.GetSpawnpoint());
            }
            else
            {
                foundMap = GetMapByName(ConstantValues.DefaultMap);
            }
            foundMap.AssignToLayer(scene, login);
        }
Esempio n. 6
0
        public static CharacterPlayer FindCharacterByID(long uniqueID)
        {
            LoginManagerServer login = GetLoginByID(uniqueID);

            if (login != null)
            {
                return(login.GetCharacter());
            }
            return(null);
        }
Esempio n. 7
0
        private void RegisterUser(LoginManagerServer login)
        {
            //TODO: Move register to its own function
            //TODO: add better character creation later
            //TODO: Change login.username to requrested character name
            login.SetCharacter(new CharacterPlayer(0, 0, login.username, new WeaponItem[ConstantValues.EquipmentLength], new WeaponItem[ConstantValues.BaseInventoryLength])
            {
                LastMultiLocation = ConstantValues.DefaultMap
            });
            string tempC = Newtonsoft.Json.JsonConvert.SerializeObject(login.GetCharacter(), new StringEnumConverter());

            SQLManager.AddToSQL(login.username, login.password, tempC);
        }
Esempio n. 8
0
        private void LoginAttempt(NetIncomingMessage message, MessageTemplate template)
        {
            LoginManagerServer LoginManagerServerUser = Newtonsoft.Json.JsonConvert.DeserializeObject <LoginManagerServer>(template.JsonMessage, new StringEnumConverter());

            LoginManagerServerUser.SetUniqueID(message.SenderConnection.RemoteUniqueIdentifier);
            Console.WriteLine("Login attempt by: " + LoginManagerServerUser.username);
            NetConnection sender = message.SenderConnection;

            if (SQLManager.CheckIfExistInSQL(LoginManagerServerUser.username))
            {
                //true if logged in
                bool   success = LoginManagerServerUser.SetupLogin();
                Entity e       = Scene.FindEntity(LoginManagerServerUser.GetCharacter()._name);
                if (success && e == null)
                {
                    Console.WriteLine("Logged in with \"" + LoginManagerServerUser.username + "\" to Database");
                    string          characterString     = Newtonsoft.Json.JsonConvert.SerializeObject(LoginManagerServerUser.GetCharacter(), new StringEnumConverter());
                    MessageTemplate TempMessageTemplate = new MessageTemplate(characterString, MessageType.LoginSuccess);

                    //Returns the character to the player
                    NetOutgoingMessage mvmntMessage = ServerNetworkSceneComponent.GetNetServer().CreateMessage(Newtonsoft.Json.JsonConvert.SerializeObject(TempMessageTemplate, new StringEnumConverter()));
                    sender.SendMessage(mvmntMessage, NetDeliveryMethod.ReliableOrdered, 0);
                    MapContainer.AssignLogin(Scene, LoginManagerServerUser);
                }
                else
                {
                    MessageTemplate    temp         = new MessageTemplate("Failure.", MessageType.LoginFailure);
                    NetOutgoingMessage mvmntMessage = ServerNetworkSceneComponent.GetNetServer().CreateMessage(Newtonsoft.Json.JsonConvert.SerializeObject(temp, new StringEnumConverter()));
                    sender.SendMessage(mvmntMessage, NetDeliveryMethod.ReliableOrdered, 0);
                }
            }
            else
            {
                MessageTemplate    temp         = new MessageTemplate("Failure.", MessageType.LoginFailure);
                NetOutgoingMessage mvmntMessage = ServerNetworkSceneComponent.GetNetServer().CreateMessage(Newtonsoft.Json.JsonConvert.SerializeObject(temp, new StringEnumConverter()));
                sender.SendMessage(mvmntMessage, NetDeliveryMethod.ReliableOrdered, 0);
            }
        }