示例#1
0
        private void PacketHandler_0x02_CreateA(Client client, ClientPacket packet)
        {
            var name     = packet.ReadString8();
            var password = packet.ReadString8();
            var email    = packet.ReadString8();

            // This string will contain a client-ready message if the provided password
            // isn't valid.
            byte passwordErr = 0x0;

            if (Game.World.PlayerExists(name))
            {
                client.LoginMessage("That name is unavailable.", 3);
            }
            else if (name.Length < 4 || name.Length > 12)
            {
                client.LoginMessage("Names must be between 4 to 12 characters long.", 3);
            }
            else if (!ValidPassword(password, out passwordErr))
            {
                client.LoginMessage(GetPasswordError(passwordErr), 3);
            }
            else if (Regex.IsMatch(name, "^[A-Za-z]{4,12}$"))
            {
                client.NewCharacterName     = name;
                client.NewCharacterPassword = HashPassword(password);
                client.LoginMessage("\0", 0);
            }
            else
            {
                client.LoginMessage("Names may only contain letters.", 3);
            }
        }
示例#2
0
文件: Login.cs 项目: DomGrieco/server
        private void PacketHandler_0x02_CreateA(Client client, ClientPacket packet)
        {
            var name = packet.ReadString8();
            var password = packet.ReadString8();
            var email = packet.ReadString8();

            // This string will contain a client-ready message if the provided password
            // isn't valid.
            byte passwordErr = 0x0;

            if (Game.World.PlayerExists(name))
            {
                client.LoginMessage("That name is unavailable.", 3);
            }
            else if (name.Length < 4 || name.Length > 12)
            {
                client.LoginMessage("Names must be between 4 to 12 characters long.", 3);
            }
            else if (!ValidPassword(password, out passwordErr))
            {
                client.LoginMessage(GetPasswordError(passwordErr), 3);
            }
            else if (Regex.IsMatch(name, "^[A-Za-z]{4,12}$"))
            {
                client.NewCharacterName = name;
                client.NewCharacterPassword = HashPassword(password);
                client.LoginMessage("\0", 0);
            }
            else
            {
                client.LoginMessage("Names may only contain letters.", 3);
            }
        }
示例#3
0
        private void PacketHandler_0x03_Login(Client client, ClientPacket packet)
        {
            var name     = packet.ReadString8();
            var password = packet.ReadString8();

            GameLog.DebugFormat("cid {0}: Login request for {1}", client.ConnectionId, name);

            if (!World.PlayerExists(name))
            {
                client.LoginMessage("That character does not exist", 3);
                GameLog.InfoFormat("cid {0}: attempt to login as nonexistent character {1}", client.ConnectionId, name);
                return;
            }

            if (World.TryGetUser(name, out User loginUser))
            {
                if (loginUser.VerifyPassword(password))
                {
                    GameLog.DebugFormat("cid {0}: password verified for {1}", client.ConnectionId, name);

                    if (Game.World.WorldData.ContainsKey <User>(name))
                    {
                        GameLog.InfoFormat("cid {0}: {1} logging on again, disconnecting previous connection",
                                           client.ConnectionId, name);
                        client.LoginMessage("That character is already online. Please try again.", 3);
                        World.ControlMessageQueue.Add(new HybrasylControlMessage(ControlOpcodes.LogoffUser, name));
                        return;
                    }

                    GameLog.DebugFormat("cid {0} ({1}): logging in", client.ConnectionId, name);
                    client.LoginMessage("\0", 0);
                    client.SendMessage("Welcome to Hybrasyl!", 3);
                    GameLog.DebugFormat("cid {0} ({1}): sending redirect to world", client.ConnectionId, name);

                    var redirect = new Redirect(client, this, Game.World, name, client.EncryptionSeed,
                                                client.EncryptionKey);
                    GameLog.InfoFormat("cid {0} ({1}): login successful, redirecting to world server",
                                       client.ConnectionId, name);
                    loginUser.Login.LastLogin     = DateTime.Now;
                    loginUser.Login.LastLoginFrom = ((IPEndPoint)client.Socket.RemoteEndPoint).Address.ToString();
                    loginUser.Save();
                    client.Redirect(redirect);
                }
                else
                {
                    GameLog.WarningFormat("cid {0} ({1}): password incorrect", client.ConnectionId, name);
                    client.LoginMessage("Incorrect password", 3);
                    loginUser.Login.LastLoginFailure = DateTime.Now;
                    loginUser.Login.LoginFailureCount++;
                    loginUser.Save();
                }
            }
            else
            {
                // Something bad has happened
                client.LoginMessage("An unknown error occurred. Please contact Hybrasyl support.", 3);
            }
        }
示例#4
0
文件: Login.cs 项目: saroque/server
        // Chart for all error password-related error codes were provided by kojasou@ on
        // https://github.com/hybrasyl/server/pull/11.
        private void PacketHandler_0x26_ChangePassword(Client client, ClientPacket packet)
        {
            var name        = packet.ReadString8();
            var currentPass = packet.ReadString8();
            // Clientside validation ensures that the same string is typed twice for the new
            // password, and the new password is only sent to the server once. We can assume
            // that they matched if 0x26 request is sent from the client.
            var newPass = packet.ReadString8();

            using (var ctx = new hybrasylEntities(Constants.ConnectionString))
            {
                var player = ctx.players.Where(p => p.name == name).SingleOrDefault();

                // Check that `name` exists. If not, return a message indicating that to the user.
                if (player == null)
                {
                    client.LoginMessage(GetPasswordError(0x0E), 0x0E);
                    Logger.DebugFormat("Password change attempt on invalid player `{0}`", name);
                }
                // If the player does exist, validate the current and new passwords before updating.
                else
                {
                    // Check that the current password is correct and the new password is different
                    // than the current password.
                    if (VerifyPassword(currentPass, player))
                    {
                        // Check if the password is valid.
                        byte err = 0x00;
                        if (ValidPassword(newPass, out err))
                        {
                            player.password_hash = HashPassword(newPass);
                            ctx.SaveChanges();

                            // Let the user know the good news.
                            client.LoginMessage("Your password has been changed successfully.", 0x0);
                            Logger.InfoFormat("Password successfully changed for `{0}`", name);
                        }
                        else
                        {
                            client.LoginMessage(GetPasswordError(err), err);
                            Logger.ErrorFormat("Invalid new password proposed during password change attempt for `{0}`", name);
                        }
                    }
                    // The current password is incorrect. Don't allow any changes to happen.
                    else
                    {
                        client.LoginMessage(GetPasswordError(0x0F), 0x0F);
                        Logger.ErrorFormat("Invalid current password during password change attempt for `{0}`", name);
                    }
                }
            }
        }
示例#5
0
文件: Login.cs 项目: saroque/server
        private void PacketHandler_0x03_Login(Client client, ClientPacket packet)
        {
            var name     = packet.ReadString8();
            var password = packet.ReadString8();

            Logger.DebugFormat("cid {0}: Login request for {1}", client.ConnectionId, name);

            using (var ctx = new hybrasylEntities(Constants.ConnectionString))
            {
                var result = ctx.players.Where(player => player.name == name).SingleOrDefault();

                if (result == null)
                {
                    client.LoginMessage("That character does not exist", 3);
                    Logger.InfoFormat("cid {0}: attempt to login as nonexistent character {1}", client.ConnectionId, name);
                }
                else
                {
                    if (VerifyPassword(password, result))
                    {
                        Logger.DebugFormat("cid {0}: password verified for {1}", client.ConnectionId, name);

                        if (Game.World.ActiveUsersByName.ContainsKey(name))
                        {
                            Logger.InfoFormat("cid {0}: {1} logging on again, disconnecting previous connection",
                                              client.ConnectionId, name);
                            World.MessageQueue.Add(new HybrasylControlMessage(ControlOpcodes.LogoffUser, name));
                        }

                        Logger.DebugFormat("cid {0} ({1}): logging in", client.ConnectionId, name);
                        client.LoginMessage("\0", 0);
                        client.SendMessage("Welcome to Hybrasyl!", 3);
                        Logger.DebugFormat("cid {0} ({1}): sending redirect to world", client.ConnectionId, name);

                        var redirect = new Redirect(client, this, Game.World, name, client.EncryptionSeed,
                                                    client.EncryptionKey);
                        Logger.InfoFormat("cid {0} ({1}): login successful, redirecting to world server",
                                          client.ConnectionId, name);
                        client.Redirect(redirect);
                    }
                    else
                    {
                        Logger.WarnFormat("cid {0} ({1}): password incorrect", client.ConnectionId, name);
                        client.LoginMessage("Incorrect password", 3);
                    }
                }
            }
        }
示例#6
0
        private void PacketHandler_0x03_Login(Client client, ClientPacket packet)
        {
            var name     = packet.ReadString8();
            var password = packet.ReadString8();

            Logger.DebugFormat("cid {0}: Login request for {1}", client.ConnectionId, name);

            User loginUser;

            if (!World.TryGetUser(name, out loginUser))
            {
                client.LoginMessage("That character does not exist", 3);
                Logger.InfoFormat("cid {0}: attempt to login as nonexistent character {1}", client.ConnectionId, name);
            }
            else if (loginUser.VerifyPassword(password))
            {
                Logger.DebugFormat("cid {0}: password verified for {1}", client.ConnectionId, name);

                if (Game.World.ActiveUsersByName.ContainsKey(name))
                {
                    Logger.InfoFormat("cid {0}: {1} logging on again, disconnecting previous connection",
                                      client.ConnectionId, name);
                    World.MessageQueue.Add(new HybrasylControlMessage(ControlOpcodes.LogoffUser, name));
                }

                Logger.DebugFormat("cid {0} ({1}): logging in", client.ConnectionId, name);
                client.LoginMessage("\0", 0);
                client.SendMessage("Welcome to Hybrasyl!", 3);
                Logger.DebugFormat("cid {0} ({1}): sending redirect to world", client.ConnectionId, name);

                var redirect = new Redirect(client, this, Game.World, name, client.EncryptionSeed,
                                            client.EncryptionKey);
                Logger.InfoFormat("cid {0} ({1}): login successful, redirecting to world server",
                                  client.ConnectionId, name);
                client.Redirect(redirect);
                loginUser.Login.LastLogin     = DateTime.Now;
                loginUser.Login.LastLoginFrom = ((IPEndPoint)client.Socket.RemoteEndPoint).Address.ToString();
                loginUser.Save();
            }
            else
            {
                Logger.WarnFormat("cid {0} ({1}): password incorrect", client.ConnectionId, name);
                client.LoginMessage("Incorrect password", 3);
                loginUser.Login.LastLoginFailure = DateTime.Now;
                loginUser.Login.LoginFailureCount++;
                loginUser.Save();
            }
        }
示例#7
0
        // Chart for all error password-related error codes were provided by kojasou@ on
        // https://github.com/hybrasyl/server/pull/11.
        private void PacketHandler_0x26_ChangePassword(Client client, ClientPacket packet)
        {
            var name        = packet.ReadString8();
            var currentPass = packet.ReadString8();
            // Clientside validation ensures that the same string is typed twice for the new
            // password, and the new password is only sent to the server once. We can assume
            // that they matched if 0x26 request is sent from the client.
            var newPass = packet.ReadString8();

            // TODO: REDIS

            User player;

            if (!World.TryGetUser(name, out player))
            {
                client.LoginMessage(GetPasswordError(0x0E), 0x0E);
                Logger.InfoFormat("cid {0}: Password change attempt on nonexistent player {1}", client.ConnectionId, name);
                return;
            }

            if (player.VerifyPassword(currentPass))
            {
                // Check if the password is valid.
                byte err = 0x00;
                if (ValidPassword(newPass, out err))
                {
                    player.Password.Hash            = HashPassword(newPass);
                    player.Password.LastChanged     = DateTime.Now;
                    player.Password.LastChangedFrom = ((IPEndPoint)client.Socket.RemoteEndPoint).Address.ToString();
                    player.Save();
                    // Let the user know the good news.
                    client.LoginMessage("Your password has been changed successfully.", 0x0);
                    Logger.InfoFormat("Password successfully changed for `{0}`", name);
                }
                else
                {
                    client.LoginMessage(GetPasswordError(err), err);
                    Logger.ErrorFormat("Invalid new password proposed during password change attempt for `{0}`", name);
                }
            }
            // The current password is incorrect. Don't allow any changes to happen.
            else
            {
                client.LoginMessage(GetPasswordError(0x0F), 0x0F);
                Logger.ErrorFormat("Invalid current password during password change attempt for `{0}`", name);
            }
        }
示例#8
0
        private void PacketHandler_0x04_CreateB(Client client, ClientPacket packet)
        {
            if (string.IsNullOrEmpty(client.NewCharacterName) || string.IsNullOrEmpty(client.NewCharacterPassword))
            {
                return;
            }
            var hairStyle = packet.ReadByte();
            var sex       = packet.ReadByte();
            var hairColor = packet.ReadByte();

            if (hairStyle < 1)
            {
                hairStyle = 1;
            }

            if (hairStyle > 17)
            {
                hairStyle = 17;
            }

            if (hairColor > 13)
            {
                hairColor = 13;
            }

            if (sex < 1)
            {
                sex = 1;
            }

            if (sex > 2)
            {
                sex = 2;
            }

            // Try to get our map
            // TODO: replace with XML config for start map, x, y
            Map map;

            if (!Game.World.WorldData.TryGetValue(136, out map))
            {
                map = Game.World.WorldData.GetDictionary <Map>().First().Value;
            }
            if (!Game.World.PlayerExists(client.NewCharacterName))
            {
                var newPlayer = new User();
                newPlayer.Name = client.NewCharacterName;
                newPlayer.Sex  = (Sex)sex;
                newPlayer.Location.Direction = Direction.South;
                newPlayer.Location.Map       = map;
                newPlayer.Location.X         = 10;
                newPlayer.Location.Y         = 10;
                newPlayer.HairColor          = hairColor;
                newPlayer.HairStyle          = hairStyle;
                newPlayer.Class                    = Class.Peasant;
                newPlayer.Gold                     = 0;
                newPlayer.Login.CreatedTime        = DateTime.Now;
                newPlayer.Password.Hash            = client.NewCharacterPassword;
                newPlayer.Password.LastChanged     = DateTime.Now;
                newPlayer.Password.LastChangedFrom = ((IPEndPoint)client.Socket.RemoteEndPoint).Address.ToString();
                newPlayer.Nation                   = Game.World.DefaultNation;

                IDatabase cache    = World.DatastoreConnection.GetDatabase();
                var       myPerson = JsonConvert.SerializeObject(newPlayer);
                cache.Set(User.GetStorageKey(newPlayer.Name), myPerson);

//                    Logger.ErrorFormat("Error saving new player!");
//                  Logger.ErrorFormat(e.ToString());
//                client.LoginMessage("Unknown error. Contact [email protected]", 3);
//          }
                client.LoginMessage("\0", 0);
            }
        }
示例#9
0
文件: Login.cs 项目: DomGrieco/server
        // Chart for all error password-related error codes were provided by kojasou@ on
        // https://github.com/hybrasyl/server/pull/11.
        private void PacketHandler_0x26_ChangePassword(Client client, ClientPacket packet)
        {
            var name = packet.ReadString8();
            var currentPass = packet.ReadString8();
            // Clientside validation ensures that the same string is typed twice for the new
            // password, and the new password is only sent to the server once. We can assume
            // that they matched if 0x26 request is sent from the client.
            var newPass = packet.ReadString8();

            // TODO: REDIS

            IDatabase cache = World.DatastoreConnection.GetDatabase();
            var myPerson = cache.Get(name);

            if (myPerson == null)
            {
                client.LoginMessage(GetPasswordError(0x0E), 0x0E);
                Logger.DebugFormat("Password change attempt on invalid player `{0}`", name);
                
            }

            var player = JsonConvert.DeserializeObject(myPerson as String) as User;
            if (player.VerifyPassword(currentPass))
            {

                // Check if the password is valid.
                byte err = 0x00;
                if (ValidPassword(newPass, out err))
                {
                    player.Password.Hash = HashPassword(newPass);
                    player.Password.LastChanged = DateTime.Now;
                    player.Password.LastChangedFrom = ((IPEndPoint) client.Socket.RemoteEndPoint).Address.ToString();
                    player.Save();
                    // Let the user know the good news.
                    client.LoginMessage("Your password has been changed successfully.", 0x0);
                    Logger.InfoFormat("Password successfully changed for `{0}`", name);
                }
                else
                {
                    client.LoginMessage(GetPasswordError(err), err);
                    Logger.ErrorFormat("Invalid new password proposed during password change attempt for `{0}`", name);
                }
            }
                // The current password is incorrect. Don't allow any changes to happen.
            else
            {
                client.LoginMessage(GetPasswordError(0x0F), 0x0F);
                Logger.ErrorFormat("Invalid current password during password change attempt for `{0}`", name);
            }
        }
示例#10
0
文件: Login.cs 项目: DomGrieco/server
        private void PacketHandler_0x04_CreateB(Client client, ClientPacket packet)
        {
            if (string.IsNullOrEmpty(client.NewCharacterName) || string.IsNullOrEmpty(client.NewCharacterPassword))
                return;

            var hairStyle = packet.ReadByte();
            var sex = packet.ReadByte();
            var hairColor = packet.ReadByte();

            if (hairStyle < 1)
                hairStyle = 1;

            if (hairStyle > 17)
                hairStyle = 17;

            if (hairColor > 13)
                hairColor = 13;

            if (sex < 1)
                sex = 1;

            if (sex > 2)
                sex = 2;

            if (!Game.World.PlayerExists(client.NewCharacterName))
            {
                var newPlayer = new User();
                newPlayer.Name = client.NewCharacterName;
                newPlayer.Sex = (Sex) sex;
                newPlayer.Location.Direction = Direction.South;
                newPlayer.Location.MapId = 136;
                newPlayer.Location.X = 10;
                newPlayer.Location.Y = 10;
                newPlayer.HairColor = hairColor;
                newPlayer.HairStyle = hairStyle;
                newPlayer.Class = Class.Peasant;
                newPlayer.Level = 1;
                newPlayer.Experience = 1;
                newPlayer.Level = 1;
                newPlayer.Experience = 0;
                newPlayer.AbilityExp = 0;
                newPlayer.Gold = 0;
                newPlayer.Ability = 0;
                newPlayer.Hp = 50;
                newPlayer.Mp = 50;
                newPlayer.BaseHp = 50;
                newPlayer.BaseMp = 50;
                newPlayer.BaseStr = 3;
                newPlayer.BaseInt = 3;
                newPlayer.BaseWis = 3;
                newPlayer.BaseCon = 3;
                newPlayer.BaseDex = 3;
                newPlayer.Login.CreatedTime = DateTime.Now;
                newPlayer.Password.Hash = client.NewCharacterPassword;
                newPlayer.Password.LastChanged = DateTime.Now;
                newPlayer.Password.LastChangedFrom = ((IPEndPoint) client.Socket.RemoteEndPoint).Address.ToString();

                IDatabase cache = World.DatastoreConnection.GetDatabase();
                var myPerson = JsonConvert.SerializeObject(newPlayer);
                    cache.Set(String.Format("{0}:{1}", User.DatastorePrefix, newPlayer.Name), myPerson);

//                    Logger.ErrorFormat("Error saving new player!");
  //                  Logger.ErrorFormat(e.ToString());
    //                client.LoginMessage("Unknown error. Contact [email protected]", 3);
      //          }
                client.LoginMessage("\0", 0);
            }
        }
示例#11
0
文件: Login.cs 项目: DomGrieco/server
        private void PacketHandler_0x03_Login(Client client, ClientPacket packet)
        {
            var name = packet.ReadString8();
            var password = packet.ReadString8();
            Logger.DebugFormat("cid {0}: Login request for {1}", client.ConnectionId, name);

            User loginUser;

            if (!World.TryGetUser(name, out loginUser))
            {
                client.LoginMessage("That character does not exist", 3);
                Logger.InfoFormat("cid {0}: attempt to login as nonexistent character {1}", client.ConnectionId, name);

            }
            else if (loginUser.VerifyPassword(password))
            {
                Logger.DebugFormat("cid {0}: password verified for {1}", client.ConnectionId, name);

                if (Game.World.ActiveUsersByName.ContainsKey(name))
                {
                    Logger.InfoFormat("cid {0}: {1} logging on again, disconnecting previous connection",
                        client.ConnectionId, name);
                    World.MessageQueue.Add(new HybrasylControlMessage(ControlOpcodes.LogoffUser, name));
                }

                Logger.DebugFormat("cid {0} ({1}): logging in", client.ConnectionId, name);
                client.LoginMessage("\0", 0);
                client.SendMessage("Welcome to Hybrasyl!", 3);
                Logger.DebugFormat("cid {0} ({1}): sending redirect to world", client.ConnectionId, name);

                var redirect = new Redirect(client, this, Game.World, name, client.EncryptionSeed,
                    client.EncryptionKey);
                Logger.InfoFormat("cid {0} ({1}): login successful, redirecting to world server",
                    client.ConnectionId, name);
                client.Redirect(redirect);
                loginUser.Login.LastLogin = DateTime.Now;
                loginUser.Login.LastLoginFrom = ((IPEndPoint) client.Socket.RemoteEndPoint).Address.ToString();
                loginUser.Save();
            }
            else
            {
                Logger.WarnFormat("cid {0} ({1}): password incorrect", client.ConnectionId, name);
                client.LoginMessage("Incorrect password", 3);
                loginUser.Login.LastLoginFailure = DateTime.Now;
                loginUser.Login.LoginFailureCount++;
                loginUser.Save();
            }
        }
示例#12
0
文件: Login.cs 项目: saroque/server
        private void PacketHandler_0x04_CreateB(Client client, ClientPacket packet)
        {
            if (string.IsNullOrEmpty(client.NewCharacterName) || string.IsNullOrEmpty(client.NewCharacterPassword))
                return;

            var hairStyle = packet.ReadByte();
            var sex = packet.ReadByte();
            var hairColor = packet.ReadByte();

            if (hairStyle < 1)
                hairStyle = 1;

            if (hairStyle > 17)
                hairStyle = 17;

            if (hairColor > 13)
                hairColor = 13;

            if (sex < 1)
                sex = 1;

            if (sex > 2)
                sex = 2;

            if (!Game.World.PlayerExists(client.NewCharacterName))
            {
                using (var ctx = new hybrasylEntities(Constants.ConnectionString))
                {
                    player newplayer = new player
                    {
                        name = client.NewCharacterName,
                        password_hash = client.NewCharacterPassword,
                        sex = (Sex) sex,
                        hairstyle = hairStyle,
                        haircolor = hairColor,
                        map_id = 136,
                        map_x = 10,
                        map_y = 10,
                        direction = 1,
                        class_type = 0,
                        level = 1,
                        exp = 0,
                        ab = 0,
                        gold = 0,
                        ab_exp = 0,
                        max_hp = 50,
                        max_mp = 50,
                        cur_hp = 50,
                        cur_mp = 35,
                        str = 3,
                        @int = 3,
                        wis = 3,
                        con = 3,
                        dex = 3,
                        inventory = "[]",
                        equipment = "[]",
                        created_at = DateTime.Now
                    };
                    try
                    {
                        ctx.players.Add(newplayer);
                        ctx.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        Logger.ErrorFormat("Error saving new player!");
                        Logger.ErrorFormat(e.ToString());
                        client.LoginMessage("Unknown error. Contact [email protected]", 3);
                    }
                    client.LoginMessage("\0", 0);
                }
            }
        }
示例#13
0
        private void PacketHandler_0x04_CreateB(Client client, ClientPacket packet)
        {
            if (string.IsNullOrEmpty(client.NewCharacterName) || string.IsNullOrEmpty(client.NewCharacterPassword))
            {
                return;
            }

            var hairStyle = packet.ReadByte();
            var sex       = packet.ReadByte();
            var hairColor = packet.ReadByte();

            if (hairStyle < 1)
            {
                hairStyle = 1;
            }

            if (hairStyle > 17)
            {
                hairStyle = 17;
            }

            if (hairColor > 13)
            {
                hairColor = 13;
            }

            if (sex < 1)
            {
                sex = 1;
            }

            if (sex > 2)
            {
                sex = 2;
            }

            if (!Game.World.PlayerExists(client.NewCharacterName))
            {
                var newPlayer = new User();
                newPlayer.Name = client.NewCharacterName;
                newPlayer.Sex  = (Sex)sex;
                newPlayer.Location.Direction = Direction.South;
                newPlayer.Location.MapId     = 136;
                newPlayer.Location.X         = 10;
                newPlayer.Location.Y         = 10;
                newPlayer.HairColor          = hairColor;
                newPlayer.HairStyle          = hairStyle;
                newPlayer.Class                    = Class.Peasant;
                newPlayer.Level                    = 1;
                newPlayer.Experience               = 1;
                newPlayer.Level                    = 1;
                newPlayer.Experience               = 0;
                newPlayer.AbilityExp               = 0;
                newPlayer.Gold                     = 0;
                newPlayer.Ability                  = 0;
                newPlayer.Hp                       = 50;
                newPlayer.Mp                       = 50;
                newPlayer.BaseHp                   = 50;
                newPlayer.BaseMp                   = 50;
                newPlayer.BaseStr                  = 3;
                newPlayer.BaseInt                  = 3;
                newPlayer.BaseWis                  = 3;
                newPlayer.BaseCon                  = 3;
                newPlayer.BaseDex                  = 3;
                newPlayer.Login.CreatedTime        = DateTime.Now;
                newPlayer.Password.Hash            = client.NewCharacterPassword;
                newPlayer.Password.LastChanged     = DateTime.Now;
                newPlayer.Password.LastChangedFrom = ((IPEndPoint)client.Socket.RemoteEndPoint).Address.ToString();
                newPlayer.Nation                   = Game.World.DefaultNation;

                IDatabase cache    = World.DatastoreConnection.GetDatabase();
                var       myPerson = JsonConvert.SerializeObject(newPlayer);
                cache.Set(User.GetStorageKey(newPlayer.Name), myPerson);

//                    Logger.ErrorFormat("Error saving new player!");
//                  Logger.ErrorFormat(e.ToString());
//                client.LoginMessage("Unknown error. Contact [email protected]", 3);
//          }
                client.LoginMessage("\0", 0);
            }
        }
示例#14
0
文件: Login.cs 项目: saroque/server
        private void PacketHandler_0x03_Login(Client client, ClientPacket packet)
        {
            var name = packet.ReadString8();
            var password = packet.ReadString8();
            Logger.DebugFormat("cid {0}: Login request for {1}", client.ConnectionId, name);

            using (var ctx = new hybrasylEntities(Constants.ConnectionString))
            {

                var result = ctx.players.Where(player => player.name == name).SingleOrDefault();

                if (result == null)
                {
                    client.LoginMessage("That character does not exist", 3);
                    Logger.InfoFormat("cid {0}: attempt to login as nonexistent character {1}", client.ConnectionId, name);
                }
                else
                {
                    if (VerifyPassword(password, result))
                    {
                        Logger.DebugFormat("cid {0}: password verified for {1}", client.ConnectionId, name);

                        if (Game.World.ActiveUsersByName.ContainsKey(name))
                        {
                            Logger.InfoFormat("cid {0}: {1} logging on again, disconnecting previous connection",
                                client.ConnectionId, name);
                            World.MessageQueue.Add(new HybrasylControlMessage(ControlOpcodes.LogoffUser, name));
                        }

                        Logger.DebugFormat("cid {0} ({1}): logging in", client.ConnectionId, name);
                        client.LoginMessage("\0", 0);
                        client.SendMessage("Welcome to Hybrasyl!", 3);
                        Logger.DebugFormat("cid {0} ({1}): sending redirect to world", client.ConnectionId, name);

                        var redirect = new Redirect(client, this, Game.World, name, client.EncryptionSeed,
                            client.EncryptionKey);
                        Logger.InfoFormat("cid {0} ({1}): login successful, redirecting to world server",
                            client.ConnectionId, name);
                        client.Redirect(redirect);
                    }
                    else
                    {
                        Logger.WarnFormat("cid {0} ({1}): password incorrect", client.ConnectionId, name);
                        client.LoginMessage("Incorrect password", 3);
                    }
                }
            }
        }
示例#15
0
文件: Login.cs 项目: saroque/server
        // Chart for all error password-related error codes were provided by kojasou@ on
        // https://github.com/hybrasyl/server/pull/11.
        private void PacketHandler_0x26_ChangePassword(Client client, ClientPacket packet)
        {
            var name = packet.ReadString8();
            var currentPass = packet.ReadString8();
            // Clientside validation ensures that the same string is typed twice for the new
            // password, and the new password is only sent to the server once. We can assume
            // that they matched if 0x26 request is sent from the client.
            var newPass = packet.ReadString8();

            using (var ctx = new hybrasylEntities(Constants.ConnectionString))
            {
                var player = ctx.players.Where(p => p.name == name).SingleOrDefault();

                // Check that `name` exists. If not, return a message indicating that to the user.
                if (player == null)
                {
                    client.LoginMessage(GetPasswordError(0x0E), 0x0E);
                    Logger.DebugFormat("Password change attempt on invalid player `{0}`", name);
                }
                // If the player does exist, validate the current and new passwords before updating.
                else
                {
                    // Check that the current password is correct and the new password is different
                    // than the current password.
                    if (VerifyPassword(currentPass, player))
                    {
                        // Check if the password is valid.
                        byte err = 0x00;
                        if (ValidPassword(newPass, out err))
                        {
                            player.password_hash = HashPassword(newPass);
                            ctx.SaveChanges();

                            // Let the user know the good news.
                            client.LoginMessage("Your password has been changed successfully.", 0x0);
                            Logger.InfoFormat("Password successfully changed for `{0}`", name);
                        }
                        else
                        {
                            client.LoginMessage(GetPasswordError(err), err);
                            Logger.ErrorFormat("Invalid new password proposed during password change attempt for `{0}`", name);
                        }
                    }
                    // The current password is incorrect. Don't allow any changes to happen.
                    else
                    {
                        client.LoginMessage(GetPasswordError(0x0F), 0x0F);
                        Logger.ErrorFormat("Invalid current password during password change attempt for `{0}`", name);
                    }
                }
            }
        }
示例#16
0
文件: Login.cs 项目: saroque/server
        private void PacketHandler_0x04_CreateB(Client client, ClientPacket packet)
        {
            if (string.IsNullOrEmpty(client.NewCharacterName) || string.IsNullOrEmpty(client.NewCharacterPassword))
            {
                return;
            }

            var hairStyle = packet.ReadByte();
            var sex       = packet.ReadByte();
            var hairColor = packet.ReadByte();

            if (hairStyle < 1)
            {
                hairStyle = 1;
            }

            if (hairStyle > 17)
            {
                hairStyle = 17;
            }

            if (hairColor > 13)
            {
                hairColor = 13;
            }

            if (sex < 1)
            {
                sex = 1;
            }

            if (sex > 2)
            {
                sex = 2;
            }

            if (!Game.World.PlayerExists(client.NewCharacterName))
            {
                using (var ctx = new hybrasylEntities(Constants.ConnectionString))
                {
                    player newplayer = new player
                    {
                        name          = client.NewCharacterName,
                        password_hash = client.NewCharacterPassword,
                        sex           = (Sex)sex,
                        hairstyle     = hairStyle,
                        haircolor     = hairColor,
                        map_id        = 136,
                        map_x         = 10,
                        map_y         = 10,
                        direction     = 1,
                        class_type    = 0,
                        level         = 1,
                        exp           = 0,
                        ab            = 0,
                        gold          = 0,
                        ab_exp        = 0,
                        max_hp        = 50,
                        max_mp        = 50,
                        cur_hp        = 50,
                        cur_mp        = 35,
                        str           = 3,
                        @int          = 3,
                        wis           = 3,
                        con           = 3,
                        dex           = 3,
                        inventory     = "[]",
                        equipment     = "[]",
                        created_at    = DateTime.Now
                    };
                    try
                    {
                        ctx.players.Add(newplayer);
                        ctx.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        Logger.ErrorFormat("Error saving new player!");
                        Logger.ErrorFormat(e.ToString());
                        client.LoginMessage("Unknown error. Contact [email protected]", 3);
                    }
                    client.LoginMessage("\0", 0);
                }
            }
        }
示例#17
0
        private void PacketHandler_0x04_CreateB(Client client, ClientPacket packet)
        {
            if (string.IsNullOrEmpty(client.NewCharacterName) || string.IsNullOrEmpty(client.NewCharacterPassword))
            {
                return;
            }
            var hairStyle = packet.ReadByte();
            var gender    = packet.ReadByte();
            var hairColor = packet.ReadByte();

            if (hairStyle < 1)
            {
                hairStyle = 1;
            }

            if (hairStyle > 17)
            {
                hairStyle = 17;
            }

            if (hairColor > 13)
            {
                hairColor = 13;
            }

            if (gender < 1)
            {
                gender = 1;
            }

            if (gender > 2)
            {
                gender = 2;
            }

            // Try to get our map
            // TODO: replace with XML config for start map, x, y
            Map map;

            if (!Game.World.WorldData.TryGetValue(136, out map))
            {
                map = Game.World.WorldData.GetDictionary <Map>().First().Value;
            }
            if (!World.PlayerExists(client.NewCharacterName))
            {
                var newPlayer = new User();
                newPlayer.Uuid                     = Guid.NewGuid().ToString();
                newPlayer.Name                     = client.NewCharacterName;
                newPlayer.Gender                   = (Xml.Gender)gender;
                newPlayer.Location.Direction       = Xml.Direction.South;
                newPlayer.Location.Map             = map;
                newPlayer.Location.X               = 10;
                newPlayer.Location.Y               = 10;
                newPlayer.HairColor                = hairColor;
                newPlayer.HairStyle                = hairStyle;
                newPlayer.Class                    = Xml.Class.Peasant;
                newPlayer.Gold                     = 0;
                newPlayer.Login.CreatedTime        = DateTime.Now;
                newPlayer.Login.FirstLogin         = true;
                newPlayer.Password.Hash            = client.NewCharacterPassword;
                newPlayer.Password.LastChanged     = DateTime.Now;
                newPlayer.Password.LastChangedFrom = ((IPEndPoint)client.Socket.RemoteEndPoint).Address.ToString();
                newPlayer.Nation                   = Game.World.DefaultNation;

                IDatabase cache = World.DatastoreConnection.GetDatabase();
                cache.Set(User.GetStorageKey(newPlayer.Name), newPlayer);
                var vault = new Vault(newPlayer.Uuid);
                vault.Save();
                var parcelStore = new ParcelStore(newPlayer.Uuid);
                parcelStore.Save();
                client.LoginMessage("\0", 0);
            }
        }