/// <summary> /// 注册和登录都走这里,根据AutoLoginOrRegister区分 /// </summary> public void Login() { if (string.IsNullOrEmpty(_userName) || string.IsNullOrEmpty(_passWd)) { return; } EDebug.LogFormat("Login {0} {1} Login Or Regist {2}", _userName, _passWd, AutoLoginOrRegist); MsgHead head = new MsgHead { cmd_id = AutoLoginOrRegist ? (short)ServerMsgId.CCMD_ROLE_AUTH : (short)ServerMsgId.CCMD_ROLE_REG }; LoginMsg loginMsg = new LoginMsg { type = 0, name = _userName, passwd = _passWd }; string loginInfo = JsonUtility.ToJson(loginMsg); byte[] bMsg = System.Text.Encoding.UTF8.GetBytes(loginInfo); head.len = bMsg.Length; byte[] bHead = ProtocolByt.StructToBytes(head, 16); byte[] buffer = new byte[bHead.Length + bMsg.Length]; System.Array.Copy(bHead, buffer, bHead.Length); System.Array.Copy(bMsg, 0, buffer, bHead.Length, bMsg.Length); try { client.BeginSend(buffer, 0, buffer.Length, SocketFlags.None, null, null); } catch (Exception e) { EDebug.LogErrorFormat("Client.Login Socket Exception {0}", e.ToString()); OnDisconnect(); } }
public void LogInEvent(LoginMsg login) { Debug.Log(login.msg); LoginMsgText.text = login.msg; Invoke("ClearMsg", 3.0f); switch (login.code) { // Failed to login case "0": break; // Wrong password case "1": break; // User created case "2": http.loginUser.rank = "1"; http.loginUser.score = "0"; FindMatch(); break; // Failed to create user case "3": break; } }
public override void OnClientConnect(NetworkConnection conn) { print("OnClientConnect"); // setup handlers client.RegisterHandler(CharactersAvailableMsg.MsgId, OnClientCharactersAvailable); client.RegisterHandler(ErrorMsg.MsgId, OnClientReceivePopup); // send login packet with hashed password, so that the original one // never leaves the player's computer. // // it's recommended to use a different salt for each hash. ideally we // would store each user's salt in the database. to not overcomplicate // things, we will use the account name as salt (at least 16 bytes) string hash = Utils.PBKDF2Hash(pw, "at_least_16_byte" + id); var message = new LoginMsg { id = this.id, pw = hash }; conn.Send(LoginMsg.MsgId, message); print("login message was sent"); // call base function to make sure that client becomes "ready" //base.OnClientConnect(conn); ClientScene.Ready(conn); // from bitbucket OnClientConnect source }
public override void OnClientConnect(NetworkConnection conn) { print("OnClientConnect"); // setup handlers client.RegisterHandler(CharactersAvailableMsg.MsgId, OnClientCharactersAvailable); client.RegisterHandler(ErrorMsg.MsgId, OnClientReceivePopup); // Application.version can be modified under: // Edit -> Project Settings -> Player -> Bundle Version LoginMsg message = new LoginMsg { account = loginAccount, version = Application.version }; conn.Send(LoginMsg.MsgId, message); print("login message was sent"); // set state state = NetworkState.Handshake; // addon system hooks Utils.InvokeMany(typeof(NetworkManagerMMO), this, "OnClientConnect_", conn); // call base function to make sure that client becomes "ready" //base.OnClientConnect(conn); ClientScene.Ready(conn); // from bitbucket OnClientConnect source }
public void MergeFrom(DL_UserCheck other) { if (other == null) { return; } if (other.Ret != 0) { Ret = other.Ret; } if (other.ConId != 0L) { ConId = other.ConId; } if (other.loginMsg_ != null) { if (loginMsg_ == null) { loginMsg_ = new global::PLoginClient.CL_Login(); } LoginMsg.MergeFrom(other.LoginMsg); } if (other.dBAccount_ != null) { if (dBAccount_ == null) { dBAccount_ = new global::PDBBase.DBAccount(); } DBAccount.MergeFrom(other.DBAccount); } }
public static void ReceiveLoginMsg(CSerialize ar) { LoginMsg msg = new LoginMsg(); ar.ReadWrite(msg); msg.PrintMsg();// 显示到屏幕 }
public void Process(Socket workerSock) { LoginMsg login = new LoginMsg(); login.ReceiveFrom(workerSock); string userName = login.UserName; string userPwd = login.UserPwd; var userService = new UserService(userName, userPwd); bool loginResult = userService.CheckLogin(); if (loginResult) { OnlineUserInfo user = new OnlineUserInfo { UserName = userName, IPEnd = workerSock.RemoteEndPoint as IPEndPoint }; foreach (var s in Server.TheTcpHelper.AcceptedSockets) { NewUserOnlineMsg newUserOnlineMsg = new NewUserOnlineMsg(user.UserName, user.IPEnd.Address.ToString()); newUserOnlineMsg.Send(s); } UserService.LoginUsers.Add(user); if (!UserService.DicUserSockets.ContainsKey(user.UserName)) { UserService.DicUserSockets.Add(user.UserName, workerSock); } } var r = loginResult ? LOGIN_RESULT.OK : LOGIN_RESULT.PWD_ERROR; Console.WriteLine("{0} login {1}", userName, r); LoginResultMsg loginResultMsg = new LoginResultMsg(r); loginResultMsg.Send(workerSock); }
void OnServerLogin_Example(LoginMsg message) { if (UseMQ) { MQ.sendObject("Clients", "", message.account + " logged in"); } }
public override void OnClientConnect(NetworkConnection conn) { print("客户端已连接"); // setup handlers NetworkClient.RegisterHandler <CharactersAvailableMsg>(OnClientCharactersAvailable); NetworkClient.RegisterHandler <ErrorMsg>(OnClientError); // send login packet with hashed password, so that the original one // never leaves the player's computer. // // it's recommended to use a different salt for each hash. ideally we // would store each user's salt in the database. to not overcomplicate // things, we will use the account name as salt (at least 16 bytes) // // Application.version can be modified under: // Edit -> Project Settings -> Player -> Bundle Version string hash = Utility.PBKDF2Hash(loginPassword, passwordSalt + loginAccount); LoginMsg message = new LoginMsg { account = loginAccount, password = hash, version = Application.version }; conn.Send(message); print("登录信息已发送"); // set state state = NetworkState.Handshake; // call base function to make sure that client becomes "ready" //base.OnClientConnect(conn); ClientScene.Ready(conn); // from bitbucket OnClientConnect source }
void OnData(int i, DataStreamReader stream) { NativeArray <byte> bytes = new NativeArray <byte>(stream.Length, Allocator.Temp); stream.ReadBytes(bytes); string recMsg = Encoding.ASCII.GetString(bytes.ToArray()); NetworkHeader header = JsonUtility.FromJson <NetworkHeader>(recMsg); switch (header.cmd) { case Commands.LOGIN: LoginMsg lMsg = JsonUtility.FromJson <LoginMsg>(recMsg); Debug.Log("[Server] Client login message received! : " + lMsg.clientId); OnClientLogIn(i, lMsg.clientId); break; case Commands.PLAYER_UPDATE: PlayerUpdateMsg puMsg = JsonUtility.FromJson <PlayerUpdateMsg>(recMsg); //Debug.Log( "[Server] Player update message received! : " + puMsg.player.ToString() ); GameServerManager.Instance.UpdatePlayerCommands(puMsg.player, puMsg.commands); break; case Commands.SERVER_UPDATE: ServerUpdateMsg suMsg = JsonUtility.FromJson <ServerUpdateMsg>(recMsg); Debug.Log("[Server] Server update message received!"); break; default: Debug.Log("[Server] Unrecognized message received!"); break; } }
public bool loginUser(string user, string password) { LoginMsg m = new LoginMsg() { username = user, password = password, code = LoginRequestCode.LOGIN }; Envelope msg = new Envelope() { login = m, type = Envelope.MsgCode.LoginMsgCode }; send(msg); var loginresp = receive(0); if (loginresp != null && loginresp.loginResponse != null) { Console.WriteLine(loginresp.loginResponse.message + " " + loginresp.loginResponse.code); if (loginresp.loginResponse.code == LoginResponseMsg.ResponseCode.OK) { return(true); } throw new Exception("bad auth"); } throw new IOException("no login response"); }
public override void OnClientConnect(NetworkConnection conn) { print("OnClientConnect"); // setup handlers client.RegisterHandler(CharactersAvailableMsg.MsgId, OnClientCharactersAvailable); client.RegisterHandler(ErrorMsg.MsgId, OnClientReceivePopup); // send login packet with hashed password, so that the original one // never leaves the player's computer. // // it's recommended to use a different salt for each hash. ideally we // would store each user's salt in the database. to not overcomplicate // things, we will use the account name as salt (at least 16 bytes) // // Application.version can be modified under: // Edit -> Project Settings -> Player -> Bundle Version string hash = Utils.PBKDF2Hash(loginPassword, "at_least_16_byte" + loginAccount); LoginMsg message = new LoginMsg { account = loginAccount, password = hash, version = Application.version }; conn.Send(LoginMsg.MsgId, message); print("login message was sent"); // set state state = NetworkState.Handshake; // addon system hooks Utils.InvokeMany(typeof(NetworkManagerMMO), this, "OnClientConnect_", conn); // call base function to make sure that client becomes "ready" //base.OnClientConnect(conn); ClientScene.Ready(conn); // from bitbucket OnClientConnect source }
void OnServerLogin(NetworkConnection conn, LoginMsg message) { if (message.version == Application.version) { if (IsAllowedAccountName(message.account)) { if (Database.singleton.TryLogin(message.account, message.password)) { if (!AccountLoggedIn(message.account)) { manager.lobby[conn] = message.account; Debug.Log("login successful: " + message.account); conn.Send(new LoginSuccessMsg()); OnServerAuthenticated.Invoke(conn); } else { manager.ServerSendError(conn, "already logged in", true); } } else { manager.ServerSendError(conn, "invalid account", true); } } else { manager.ServerSendError(conn, "account name not allowed", true); } } else { manager.ServerSendError(conn, "outdated version", true); } }
/// <summary> /// 用户登录 /// </summary> /// <param name="msg"></param> /// <param name="ip"></param> /// <param name="port"></param> /// <param name="state"></param> private void UserLogin(ClassMsg msg, IPAddress ip, int port, int state) { LoginMsg loginmsg = (LoginMsg) new ClassSerializers().DeSerializeBinary(new MemoryStream(msg.Data)); ClassOptionData OptionData = new ClassOptionData(); //创建并引用ClassOptionData MsgCommand msgState = msg.msgCommand; //获取接收消息的命令 String UserName = loginmsg.UserName; //登录用户名称 String PassWord = loginmsg.PassWord; //用户密码 String vIP = ip.ToString(); //用户IP地址 DataTable DataReader = OptionData.ExSQLReDr("Select * From user Where UserAccount = " + "'" + UserName + "'" + " and UserPassWord = "******"'" + PassWord + "'");//在数据库中通过用户名和密码进行查找 if (DataReader.Rows.Count != 0) //当DataReader中有记录信息时 { string ID = DataReader.Rows[0]["UserID"].ToString(); //获取第一条记录中的ID字段值 //修改当前记录的标识为上线状态 OptionData.ExSQL("Update CurreneyUser Set Sign = " + Convert.ToString((int)(MsgCommand.Logined)) + ",IP = " + "'" + vIP + "',Port = " + "'" + port.ToString() + "'" + " Where ID = " + ID); msg.msgCommand = MsgCommand.Logined; //设置为上线命令 msg.SID = ID; //用户ID值 SendMsgToOne(ip, port, msg); //将消息返回给发送用户 UpdateUserState(msg, ip, port); //更新用户在线状态 } else { SendMsgToOne(ip, port, msg); } OptionData.Dispose(); LoadUsrLst(); //UpdateUser();//更新用户列表 }
private void SendLogin(MsgBase msg) { LoginMsg tmpMsg = (LoginMsg)msg; peer.SendOperation((byte)OpCodeEnum.Login, new Dictionary <byte, object> { { (byte)OpKeyEnum.UserName, tmpMsg.username }, { (byte)OpKeyEnum.PassWord, tmpMsg.password } }, new SendOptions()); }
void OnServerLogin(NetworkConnection conn, LoginMsg message) { Debug.Log("OnServer Login del NetworkAuthenticahtor"); // correct version? if (message.version == Application.version) { // allowed account name? if (IsAllowedAccountName(message.account)) { // validate account info if (Database.IsValidAccount(message.account, message.password)) { // not in lobby and not in world yet? if (!AccountLoggedIn(message.account)) { // add to logged in accounts manager.lobby[conn] = message.account; // login successful Debug.Log("login successful: " + message.account); // notify client about successful login. otherwise it // won't accept any further messages. conn.Send(new LoginSuccessMsg()); // authenticate on server OnServerAuthenticated.Invoke(conn); } else { //print("account already logged in: " + message.account); <- don't show on live server manager.ServerSendError(conn, "already logged in", true); // note: we should disconnect the client here, but we can't as // long as unity has no "SendAllAndThenDisconnect" function, // because then the error message would never be sent. //conn.Disconnect(); } } else { //print("invalid account or password for: " + message.account); <- don't show on live server manager.ServerSendError(conn, "invalid account", true); } } else { //print("account name not allowed: " + message.account); <- don't show on live server manager.ServerSendError(conn, "account name not allowed", true); } } else { //print("version mismatch: " + message.account + " expected:" + Application.version + " received: " + message.version); <- don't show on live server manager.ServerSendError(conn, "outdated version", true); } }
void OnServerLogin(NetworkMessage netMsg) { print("OnServerLogin " + netMsg.conn); LoginMsg message = netMsg.ReadMessage <LoginMsg>(); // correct version? if (message.version == Application.version) { // allowed account name? if (IsAllowedAccountName(message.account)) { // validate account info if (Database.IsValidAccount(message.account, message.password)) { // not in lobby and not in world yet? if (!AccountLoggedIn(message.account)) { print("login successful: " + message.account); // add to logged in accounts lobby[netMsg.conn] = message.account; // send necessary data to client CharactersAvailableMsg reply = MakeCharactersAvailableMessage(message.account); netMsg.conn.Send(CharactersAvailableMsg.MsgId, reply); // addon system hooks Utils.InvokeMany(typeof(NetworkManagerMMO), this, "OnServerLogin_", message); } else { print("account already logged in: " + message.account); ClientSendPopup(netMsg.conn, "already logged in", true); // note: we should disconnect the client here, but we can't as // long as unity has no "SendAllAndThenDisconnect" function, // because then the error message would never be sent. //netMsg.conn.Disconnect(); } } else { print("invalid account or password for: " + message.account); ClientSendPopup(netMsg.conn, "invalid account", true); } } else { print("account name not allowed: " + message.account); ClientSendPopup(netMsg.conn, "account name not allowed", true); } } else { print("version mismatch: " + message.account + " expected:" + Application.version + " received: " + message.version); ClientSendPopup(netMsg.conn, "outdated version", true); } }
/// <summary> /// 发送登录请求 /// </summary> /// <param name="account"></param> /// <param name="pwd"></param> public void SendLogin(string account, string pwd) { LoginMsg msg = new LoginMsg { accountId = account, accountPwd = pwd }; NSocket.GetInstance().SendData(Request.Login, msg); }
public override void OnClientAuthenticate(NetworkConnection conn) { string hash = Utils.PBKDF2Hash(loginPassword, passwordSalt + loginAccount); LoginMsg message = new LoginMsg { account = loginAccount, password = hash, version = Application.version }; conn.Send(message); print("login message was sent"); manager.state = NetworkState.Handshake; }
public void ReceiveFromClient() { while (true) { string receiveString = null; try { receiveString = br.ReadString(); } catch { //异常处理 } string[] spilt = receiveString.Split('@'); switch (spilt[0]) { case "RESEND": string res = DataHandle.Resend(spilt[1]); this.bw.Write(res); bw.Flush(); break; case "LOGIN": //登陆 LoginMsg msg = TalkHelper.HandleHelper.DeXMLSer <LoginMsg>(spilt[1]); string loginres = DataHandle.Login(msg.UserName, msg.Password); bw.Write(loginres); bw.Flush(); DataHandle.Default(string.Format("\n{0}-->{1}-->LOGIN", DateTime.Now.ToLongDateString(), msg.UserName)); break; case "SIGNUP": //注册 SignupMsg signupMsg = TalkHelper.HandleHelper.DeXMLSer <SignupMsg>(spilt[1]); string signupres = DataHandle.Signup(signupMsg.UserName, signupMsg.Password); this.bw.Write(signupres); bw.Flush(); //向客户端发送 DataHandle.Default(string.Format("\n{0}-->{1}-->SIGNUP", DateTime.Now.ToLongDateString(), signupMsg.UserName)); //将操作结果输出在服务器界面上 break; case "LOGOUT": //登出,暂时没有操作 break; default: try { DataHandle.Default(spilt[1]); } catch (Exception ex) { DataHandle.Default(ex.Message); } break; } } }
void OnServerLogin(NetworkConnection conn, LoginMsg message) { // correct version? if (message.version == Application.version) { // allowed account name? if (IsAllowedAccountName(message.account)) { // validate account info if (Database.singleton.TryLogin(message.account, message.password)) { // not in lobby and not in world yet? if (!AccountLoggedIn(message.account)) { //print("login successful: " + message.account); // add to logged in accounts lobby[conn] = message.account; // send necessary data to client conn.Send(MakeCharactersAvailableMessage(message.account)); // addon system hooks Utils.InvokeMany(typeof(NetworkManagerMMO), this, "OnServerLogin_", message); } else { //print("account already logged in: " + message.account); <- don't show on live server ServerSendError(conn, "already logged in", true); // note: we should disconnect the client here, but we can't as // long as unity has no "SendAllAndThenDisconnect" function, // because then the error message would never be sent. //conn.Disconnect(); } } else { //print("invalid account or password for: " + message.account); <- don't show on live server ServerSendError(conn, "invalid account", true); } } else { //print("account name not allowed: " + message.account); <- don't show on live server ServerSendError(conn, "account name not allowed", true); } } else { //print("version mismatch: " + message.account + " expected:" + Application.version + " received: " + message.version); <- don't show on live server ServerSendError(conn, "outdated version", true); } }
void OnConnect() { // TEMP : until we gets id from the database clientId = Guid.NewGuid().ToString(); Debug.Log("[Client] now connected to the server : " + clientId); // Example to send a handshake message: LoginMsg m = new LoginMsg(clientId); SendToServer(JsonUtility.ToJson(m)); }
private void btnLogin_Click(object sender, RoutedEventArgs e) { GetConnected(); string ID = txtId.Text.Trim(); string PWD = txtPwd.Password.Trim(); LoginMsg login = new LoginMsg(ID, PWD); bw.Write(string.Format("LOGIN@{0}", HandleHelper.XMLSer <LoginMsg>(login))); bw.Flush(); //ChatWindow cw = new ChatWindow(); //cw.Show(); //this.Close(); }
static void SendLoginMessage(Socket _s, String _msg) { LoginMsg loginMessage = new LoginMsg(); loginMessage.msg = _msg; MemoryStream outStream = loginMessage.WriteData(); try { _s.Send(outStream.GetBuffer()); } catch (System.Exception) { } }
void OnServerLogin(NetworkConnection conn, LoginMsg message) { // correct version? if (message.version == Application.version) { // allowed account name? if (IsAllowedAccountName(message.account)) { // validate account info if (Database.Singleton.TryLogin(message.account, message.password)) { // not in lobby and not in world yet? if (!AccountLoggedIn(message.account)) { print("登入成功: " + message.account); // add to logged in accounts lobby[conn] = message.account; // send necessary data to client conn.Send(MakeCharactersAvailableMessage(message.account)); } else { print("账户已登入 " + message.account); ServerSendError(conn, "already logged in", true); // note: we should disconnect the client here, but we can't as // long as unity has no "SendAllAndThenDisconnect" function, // because then the error message would never be sent. //conn.Disconnect(); } } else { print("无效的账户或密码: " + message.account); ServerSendError(conn, "invalid account", true); } } else { print("账户名称无效: " + message.account); ServerSendError(conn, "account name not allowed", true); } } else { print("版本不匹配: " + message.account + " expected:" + Application.version + " received: " + message.version); ServerSendError(conn, "outdated version", true); } }
private void Login() { Console.WriteLine(">LOGIN:"******">Please input your user name:"); var uName = Console.ReadLine(); UserService.LoginUserName = uName; Console.WriteLine(">Please input your password:"); var uPwd = Console.ReadLine(); LoginMsg msg = new LoginMsg(uName, uPwd); msg.Send(serverSock); }
void TestFunc0() { LoginMsg msg = new LoginMsg(); msg.szUserName = "******"; msg.szPassword = "******"; msg.nPlatType = 1; msg.szPlatName = "时空机"; CSerialize ar = new CSerialize(SerializeType.write); msg.Serialize(ar); FCLibHelper.fc_serialize_msg_call(0, "TestSerialize.ReceiveLoginMsg", ar.GetBuffer(), 0, ar.GetBufferSize(), true); }
public void OnServerLogin_UCE_UnlockableClasses(NetworkConnection conn, LoginMsg netMsg) { if (!defaultUnlockedClasses) { return; } List <string> unlockedClasses = Database.singleton.UCE_GetUnlockedClasses(netMsg.account); ClassesAvailableMsg message = new ClassesAvailableMsg { unlockedClasses = unlockedClasses.ToArray() }; conn.Send(message); }
public void sendLoginDetails(String loginDetails) { LoginMsg loginMsg = new LoginMsg(); loginMsg.msg = loginDetails; MemoryStream outStream = loginMsg.WriteData(); m_Server.Send(outStream.GetBuffer()); m_MainForm.Invoke(new MethodInvoker(delegate() { m_MainForm.m_CurrentUserName = loginDetails.Split(' ')[0]; m_MainForm.SetClientName(loginDetails.Split(' ')[0]); })); }
// Login MSG private LoginMsg GetLiMSG(byte[] msg, Int64 msgSize) { Int32 type = ByteInt32(msg[8]); byte[] seq_num = new byte[4]; byte[] vars = new byte[msgSize - 13]; Array.Copy(msg, 9, seq_num, 0, 4); Array.Copy(msg, 13, vars, 0, msgSize - 13); LoginMsg LiMSG = LiMSGVars(vars); LiMSG.msgType = type; return(LiMSG); }