protected override void Process(Networking.ServerClient s) { ushort errorCode = GetUShort(0); if (Enum.IsDefined(typeof(PlayerAuthorizationErrorCodes), errorCode)) { PlayerAuthorizationErrorCodes enumErrorCode = (PlayerAuthorizationErrorCodes)errorCode; uint targetId = GetuInt(1); switch (enumErrorCode) { // A new player logs in. case PlayerAuthorizationErrorCodes.Login: { Entities.User u = Managers.UserManager.Instance.Get(targetId); if (u != null) { uint userId = GetuInt(2); string username = GetString(3); string displayname = GetString(4); byte _accessLevel = GetByte(5); u.OnAuthorize(userId, username, displayname, _accessLevel); } break; } // Update the information of a player. case PlayerAuthorizationErrorCodes.Update: { break; } // A player logs out of the server. case PlayerAuthorizationErrorCodes.Logout: { break; } case PlayerAuthorizationErrorCodes.InvalidSession: { Entities.User u = Managers.UserManager.Instance.Get(targetId); if (u != null) { if (!u.Authorized) { u.Send(new Packets.Authorization(Packets.Authorization.ErrorCodes.NormalProcedure)); } u.Disconnect(); } break; } case PlayerAuthorizationErrorCodes.IvalidMatch: { Entities.User u = Managers.UserManager.Instance.Get(targetId); if (u != null) { u.Send(new Packets.Authorization(Packets.Authorization.ErrorCodes.NormalProcedure)); u.Disconnect(); } break; } case PlayerAuthorizationErrorCodes.SessionAlreadyActivated: { Entities.User u = Managers.UserManager.Instance.Get(targetId); if (u != null) { u.Send(new Packets.Authorization(Packets.Authorization.ErrorCodes.NormalProcedure)); u.Disconnect(); } break; } default: { // Unused. break; } } } else { Log.Instance.WriteLine(string.Concat("Unknown PlayerAuthorization error: ", errorCode)); } }
public override void Handle(ServerClient sender, InPacket packetReader) { ushort errorCode = packetReader.ReadUshort(); if (Enum.IsDefined(typeof(PlayerAuthorizationErrorCodes), errorCode)) { PlayerAuthorizationErrorCodes enumErrorCode = (PlayerAuthorizationErrorCodes)errorCode; uint targetId = packetReader.ReadUint(); switch (enumErrorCode) { // A new player logs in. case PlayerAuthorizationErrorCodes.Login: { Entities.User u = Managers.UserManager.Instance.Get(targetId); if (u != null) { uint userId = packetReader.ReadUint(); string username = packetReader.ReadString(); string displayname = packetReader.ReadString(); u.OnAuthorize(userId, username, displayname); } break; } // Update the information of a player. case PlayerAuthorizationErrorCodes.Update: { break; } // A player logs out of the server. case PlayerAuthorizationErrorCodes.Logout: { break; } case PlayerAuthorizationErrorCodes.InvalidSession: { Entities.User u = Managers.UserManager.Instance.Get(targetId); if (u != null) { if (!u.Authenticated) { u.Send(new Packets.Authorization(Packets.Authorization.ErrorCodes.NormalProcedure)); } u.Disconnect(); } break; } case PlayerAuthorizationErrorCodes.IvalidMatch: { Entities.User u = Managers.UserManager.Instance.Get(targetId); if (u != null) { u.Send(new Packets.Authorization(Packets.Authorization.ErrorCodes.NormalProcedure)); u.Disconnect(); } break; } case PlayerAuthorizationErrorCodes.SessionAlreadyActivated: { Entities.User u = Managers.UserManager.Instance.Get(targetId); if (u != null) { u.Send(new Packets.Authorization(Packets.Authorization.ErrorCodes.NormalProcedure)); u.Disconnect(); } break; } default: { // Unused. break; } } } else { Log.Instance.WriteLine(string.Concat("Unknown PlayerAuthorization error: ", errorCode)); } }
protected async override void Process(Entities.User user) { List <object> userData = new List <object>(); string inputUserName = GetString(2); string inputPassword = GetString(3); bool isSettingNewNickName = false; //valid UserName? if (inputUserName.Length >= 3 && Core.Utils.isAlphaNumeric(inputUserName)) { //is password long enough? if (inputPassword.Length >= 3) { using (Core.Databases.Database Db = new Core.Databases.Database(Config.AUTH_CONNECTION)) { userData = await Db.AsyncGetRowFromTable( new string[] { "ID", "username", "displayname", "password", "salt", "rights" }, "users", new Dictionary <string, object>() { { "username", inputUserName } }); } //Does the username exists? if (userData.Count > 0 && userData != null) { //The user does exist: retrieve data uint id = Convert.ToUInt32(userData[0]); string dbUserName = inputUserName; string displayname = userData[2].ToString(); string dbPassword = userData[3].ToString(); string dbPasswordSalt = userData[4].ToString(); GameConstants.Rights dbRights; try { dbRights = (GameConstants.Rights)Convert.ToByte(userData[5]); } catch { Log.Error("User " + dbUserName + " rights could not be parsed. Blocking user."); dbRights = GameConstants.Rights.Blocked; } //We hash password typed by the player and check it against the one stored in the DB string hashedPassword = Core.Utils.CreateSHAHash(String.Concat(inputPassword, dbPasswordSalt)); //CHECK!! Proceed if (hashedPassword == dbPassword.ToLower()) { var IsOnline = Managers.SessionManager.Instance.Sessions.Select(n => n.Value).Where(n => n.ID == id && n.IsActivated && !n.IsEnded).Count(); //Check to see if the same account is already logged in //TODO: Improve this. What if a GameServer does not update this? if (IsOnline == 0) { //TODO: Add ban time? Delegate it to game servers? //TODO: Add gameserver blacklisting if (dbRights == GameConstants.Rights.Blocked) { user.Send(new Packets.ServerList(Packets.ServerList.ErrorCodes.Banned)); } else { //Authenticate player user.OnAuthorize(id, dbUserName, displayname); //check if the player has a NickName if (user.DisplayName.Length > 0) { user.Send(new Packets.ServerList(user)); } else { if (Config.ENABLENICKCHANGE) //can they set their nickname ingame ??? { isSettingNewNickName = true; user.Send(new Packets.ServerList(Packets.ServerList.ErrorCodes.NewNickname)); } else { user.Send(new Packets.ServerList(Packets.ServerList.ErrorCodes.IlligalNickname)); } } } } else { user.Send(new Packets.ServerList(Packets.ServerList.ErrorCodes.AlreadyLoggedIn)); } } else { user.Send(new Packets.ServerList(Packets.ServerList.ErrorCodes.WrongPW)); } } else { user.Send(new Packets.ServerList(Packets.ServerList.ErrorCodes.WrongUser)); } } else { user.Send(new Packets.ServerList(Packets.ServerList.ErrorCodes.EnterPasswordError)); } } else { user.Send(new Packets.ServerList(Packets.ServerList.ErrorCodes.EnterIDError)); } //people who successfully logged on can be safely disconnected... //the client will show the server list and they will be redirected by the client. //keep the socket for those who are setting up nickname if (!isSettingNewNickName) { user.Disconnect(); } }
protected override void Process(Entities.User user) { string inputUserName = GetString(2); string inputPassword = GetString(3); bool forceDisconnect = true; //valid UserName? if (inputUserName.Length >= 3 && Core.Constants.isAlphaNumeric(inputUserName)) { //is password long enough? if (inputPassword.Length >= 3) { MySqlDataReader reader = Databases.Auth.Select( new string[] { "id", "username", "status", "displayname", "password", "passwordsalt" }, "users", new Dictionary <string, object>() { { "username", inputUserName } }); //Does the username exists? if (reader.HasRows && reader.Read()) { //The user does exist: retrieve data uint id = reader.GetUInt32(0); string dbUserName = inputUserName; byte status = reader.GetByte(2); //0 = global network account ban string displayname = reader.GetString(3); string dbPassword = reader.GetString(4); string dbPasswordSalt = reader.GetString(5); //We hash password typed by the player and check it against the one stored in the DB string hashedPassword = Core.Constants.GenerateSHAHash(String.Concat(inputPassword, dbPasswordSalt)); //CHECK!! Proceed if (hashedPassword == dbPassword.ToLower()) { var IsOnline = Managers.SessionManager.Instance.Sessions.Select(n => n.Value).Where(n => n.ID == id && n.IsActivated && !n.IsEnded).Count(); //Check to see if the same account is already logged in //TODO: Improve this. What if a GameServer does not update this? if (IsOnline == 0) { if (status > 0) { user.OnAuthorize(id, dbUserName, displayname, status); user.Send(new Packets.ServerList(user)); } else { user.Send(new Packets.ServerList(Packets.ServerList.ErrorCodes.Banned)); } } else { user.Send(new Packets.ServerList(Packets.ServerList.ErrorCodes.AlreadyLoggedIn)); } } else { user.Send(new Packets.ServerList(Packets.ServerList.ErrorCodes.WrongPW)); } } else { user.Send(new Packets.ServerList(Packets.ServerList.ErrorCodes.WrongUser)); } if (!reader.IsClosed) { reader.Close(); } } else { user.Send(new Packets.ServerList(Packets.ServerList.ErrorCodes.EnterPasswordError)); } } else { user.Send(new Packets.ServerList(Packets.ServerList.ErrorCodes.EnterIDError)); } if (forceDisconnect) { user.Disconnect(); } }