public UserCollection.UserReturn RegistNewUser(RegistInfo info) { UserCollection.UserReturn userReturn = new UserCollection.UserReturn(); if (info.Account != "siege" && info.Account != "online" && info.Account != "test") { if (info.Nickname != "abcd" && info.Nickname != "efgh" && info.Nickname != "test") { userReturn.ReturnCode = Default; userReturn.DebugMessage.Append("注册账号成功"); } else { userReturn.ReturnCode = NicknameExist; userReturn.DebugMessage.Append("昵称已被使用"); } } else { userReturn.ReturnCode = AccountExist; userReturn.DebugMessage.Append("账号名已存在"); } return(userReturn); }
/// <summary> /// 类型:方法 /// 名称:TryRegist /// 作者:taixihuase /// 作用:通过请求的角色数据,尝试创建、记录一个新的角色数据并再次返回给客户端 /// 编写日期:2015/7/14 /// </summary> /// <param name="operationRequest"></param> /// <param name="sendParameters"></param> /// <param name="peer"></param> private static void TryRegist(OperationRequest operationRequest, SendParameters sendParameters, ServerPeer peer) { ServerPeer.Log.Debug("Regist a new account..."); RegistInfo info = (RegistInfo) Serialization.Deserialize(operationRequest.Parameters[(byte)ParameterCode.Regist]); UserCollection.UserReturn userReturn = peer.Server.Users.RegistUser(info); if (userReturn.ReturnCode == UserCollection.UserReturn.ReturnCodeType.Success) { OperationResponse response = new OperationResponse((byte)OperationCode.Regist) { ReturnCode = (short)ErrorCode.Ok, DebugMessage = "账号创建成功!" }; peer.SendOperationResponse(response, sendParameters); } else { OperationResponse response = new OperationResponse((byte)OperationCode.Regist) { ReturnCode = (short)ErrorCode.InvalidOperation, DebugMessage = userReturn.DebugMessage.ToString() }; peer.SendOperationResponse(response, sendParameters); ServerPeer.Log.Debug(DateTime.Now + " : Failed to regist " + info.Account + " Because of " + Enum.GetName(typeof(UserCollection.UserReturn.ReturnCodeType), userReturn.ReturnCode)); } }
/// <summary> /// 类型:方法 /// 名称:GetUserInfo /// 作者:taixihuase /// 作用:尝试从数据库获取获取用户信息 /// 编写日期:2015/7/24 /// </summary> /// <param name="user"></param> /// <param name="password"></param> /// <returns></returns> public UserCollection.UserReturn GetUserInfo(UserInfo user, string password) { UserCollection.UserReturn userReturn = new UserCollection.UserReturn(); if (user.Account == "test" || user.Account == "siege" || user.Account == "online") { if (password == "1234") { if (user.Account == "siege") { user.UniqueId = 1; user.Nickname = "abcd"; } else if (user.Account == "online") { user.UniqueId = 2; user.Nickname = "efgh"; } else { user.UniqueId = 3; user.Nickname = "test"; } userReturn.ReturnCode = Default; userReturn.DebugMessage.Append("用户信息正确!"); } else { userReturn.ReturnCode = WrongPassword; userReturn.DebugMessage.Append("密码错误!"); } } else { userReturn.ReturnCode = Unregister; userReturn.DebugMessage.Append("该账号未注册!"); } return(userReturn); }
/// <summary> /// 类型:方法 /// 名称:TryLogin /// 作者:taixihuase /// 作用:通过登录数据尝试登录 /// 编写日期:2015/7/14 /// </summary> /// <param name="operationRequest"></param> /// <param name="sendParameters"></param> /// <param name="peer"></param> private static void TryLogin(OperationRequest operationRequest, SendParameters sendParameters, ServerPeer peer) { ServerPeer.Log.Debug("Logining..."); LoginInfo login = (LoginInfo) Serialization.Deserialize(operationRequest.Parameters[(byte)ParameterCode.Login]); #region 对账号密码进行判断 ServerPeer.Log.Debug(DateTime.Now + " : Loginning..."); ServerPeer.Log.Debug(login.Account); ServerPeer.Log.Debug(login.Password); // 获取用户资料 UserInfo user = new UserInfo(peer.PeerGuid, login.Account); UserCollection.UserReturn userReturn = peer.Server.Users.UserOnline(user, login.Password); // 若成功取得用户资料 if (userReturn.ReturnCode == UserCollection.UserReturn.ReturnCodeType.Success) { ServerPeer.Log.Debug(user.LoginTime + " :User " + user.Nickname + " loginning..."); // 用于选择的数据返回参数 var parameter = new Dictionary <byte, object>(); // 用于选择的字符串信息 string message = ""; // 用于选择的返回值 short returnCode = -1; #region 获取角色资料 Character character = new Character(user); CharacterCollection.CharacterReturn characterReturn = peer.Server.Characters.SearchCharacter(character); // 若取得角色资料 if (characterReturn.ReturnCode == CharacterCollection.CharacterReturn.ReturnCodeType.Success) { byte[] playerBytes = Serialization.Serialize(character); parameter.Add((byte)ParameterCode.Login, playerBytes); returnCode = (short)ErrorCode.Ok; message = ""; peer.Server.Characters.CharacterLoad(character); } else if (characterReturn.ReturnCode == CharacterNotFound) { byte[] userBytes = Serialization.Serialize(user); parameter.Add((byte)ParameterCode.Login, userBytes); returnCode = (short)ErrorCode.CharacterNotFound; message = characterReturn.DebugMessage.ToString(); } #endregion OperationResponse response = new OperationResponse((byte)OperationCode.Login, parameter) { ReturnCode = returnCode, DebugMessage = message }; peer.SendOperationResponse(response, sendParameters); ServerPeer.Log.Debug(user.LoginTime + " : User " + user.Account + " logins successfully"); } // 若重复登录 else if (userReturn.ReturnCode == RepeatedLogin) { OperationResponse response = new OperationResponse((byte)OperationCode.Login) { ReturnCode = (short)ErrorCode.RepeatedOperation, DebugMessage = "账号已登录!" }; peer.SendOperationResponse(response, sendParameters); ServerPeer.Log.Debug(DateTime.Now + " : Failed to login " + user.Account + " Because of " + Enum.GetName(typeof(UserCollection.UserReturn.ReturnCodeType), userReturn.ReturnCode)); } else { // 返回非法登录错误 OperationResponse response = new OperationResponse((byte)OperationCode.Login) { ReturnCode = (short)ErrorCode.InvalidOperation, DebugMessage = userReturn.DebugMessage.ToString() }; peer.SendOperationResponse(response, sendParameters); ServerPeer.Log.Debug(DateTime.Now + " : Failed to login " + user.Account + " Because of " + Enum.GetName(typeof(UserCollection.UserReturn.ReturnCodeType), userReturn.ReturnCode)); } #endregion }