public static void Handle_SetNewNickName(ClientConnection Client, PacketReader reader, byte last) { Account User = Client.CurrentAccount; bool NickNameOK = false; //preader.ReadByte(); //op code 0x4B int nicknamelen = reader.ReadLEInt32(); string nickname = reader.ReadBig5StringSafe(nicknamelen); reader.Clear(); Console.WriteLine(nickname); try { NickNameOK = SetNewNickNameCheck(Client, nickname, last); if (NickNameOK) { Client.SendAsync(new LoginGetNickName_0X1C(User, last)); CreateFarm(User.UserNum); } } catch (Exception e) { Console.WriteLine(e.Message); } }
public static void Handle_LoginCheck(ClientConnection Client, PacketReader reader) { //int packetlength = reader.ReadLEInt16(); //reader.ReadByte(); //opcode try { if (!ServerStatus.isReady) { Log.Info("connection blocked by current setting ServerReady off"); Client.SendAsync(new ServerNotReady()); return; } int useridlen = reader.ReadLEInt32(); string userid = reader.ReadStringSafe(useridlen); int passwordlen = reader.ReadLEInt32(); string password = pwdecode(reader.ReadByteArray(passwordlen)); reader.Clear(); // Console.WriteLine("User Login ( Account: {0} ,Password: {1} )", userid, password); bool UserCheckOK = checkUserAccount(userid, password); if (UserCheckOK) { Console.WriteLine("Login Success!"); //int cookie = LocalCommons.Cookie.Cookie.Generate(); //byte[] key = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00 }; byte[] randomkey = new byte[16]; RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider(); rng.GetBytes(randomkey); byte[] xorkey = Encrypt.EncryptKey(randomkey, randomkey); //Console.WriteLine("rand key {0}", Utility.ByteArrayToString(randomkey)); //Console.WriteLine("xor key {0}", Utility.ByteArrayToString(xorkey)); Account nCurrent = new Account { UserID = userid, Connection = Client, LastIp = Client.ToString(), Port = (short)((IPEndPoint)Client.CurrentChannel.RemoteEndPoint).Port, EncryptKey = randomkey, XorKey = xorkey, Session = Client.session, isLogin = false }; Client.CurrentAccount = nCurrent; //ClientConnection.CurrentAccounts.TryAdd(cookie, Client.CurrentAccount); ClientConnection.CurrentAccounts[Client.session] = nCurrent; } else { Console.WriteLine("Login Fail!"); } Client.SendAsync(new LoginServerTime_0X41()); Client.SendAsync(new LoginCheck_0X10(userid, UserCheckOK)); } catch (Exception e) { Console.WriteLine(e.Message); } }