public override void RunImpl() { if (_client.State != LoginClientState.AuthedLogin) { _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed)); _client.Close(); return; } if (_client.Key.LoginOkId1 != _loginOkID1 && _client.Key.LoginOkId2 != _loginOkID2) { _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed)); _client.Close(); return; } L2Server server = ServerThreadPool.Instance.Get(_serverId); if (server == null) { _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed)); _client.Close(); return; } if (server.Connected == 0) { _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonServerMaintenance)); _client.Close(); return; } _client.Send(PlayOk.ToPacket(_client)); }
static bool HandleCharDelete(LoginClient client, CMSG msgID, BinReader data) { uint id = data.ReadUInt32(); if (client.Account.Characters == null) { client.Close(client.Account.Name + " tried to delete a character when there was none on the account."); return(true); } foreach (DBCharacter c in client.Account.Characters) { if (id == c.ObjectId) { try { DataServer.Database.DeleteObject(c); } catch (Exception e) { Console.WriteLine("Deleting character " + c.ObjectId + " failed! " + e.Message); } client.Account.Characters = null; DataServer.Database.FillObjectRelations(client.Account); BinWriter w = LoginClient.NewPacket(SMSG.CHAR_DELETE); w.Write((byte)0x28); client.Send(w); return(true); } } client.Close(client.Account.Name + " tried to delete a character that didn't belong to him."); return(true); }
public override void RunImpl() { CipherParameters key = _client.RsaPair._privateKey; RSAEngine rsa = new RSAEngine(); rsa.init(false, key); byte[] decrypt = rsa.processBlock(Raw, 0, 128); if (decrypt.Length < 128) { byte[] temp = new byte[128]; Array.Copy(decrypt, 0, temp, 128 - decrypt.Length, decrypt.Length); decrypt = temp; } string username = Encoding.ASCII.GetString(decrypt, 0x5e, 14).Replace("\0", string.Empty); string password = Encoding.ASCII.GetString(decrypt, 0x6c, 16).Replace("\0", string.Empty); AccountModel account = AccountService.GetAccountByLogin(username); if (account == null) { if (Config.Config.Instance.ServerConfig.AutoCreate) { account = AccountService.CreateAccount(username, L2Security.HashPassword(password)); } else { _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonUserOrPassWrong)); _client.Close(); return; } } else { if (!AccountService.CheckIfAccountIsCorrect(username, L2Security.HashPassword(password))) { _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonUserOrPassWrong)); _client.Close(); return; } if (ServerThreadPool.Instance.LoggedAlready(username.ToLower())) { _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonAccountInUse)); _client.Close(); return; } } Random rnd = new Random(); _client.ActiveAccount = account; _client.SetLoginPair(rnd.Next(), rnd.Next()); _client.SetPlayPair(rnd.Next(), rnd.Next()); _client.Send(LoginOk.ToPacket(_client)); }
public override async Task RunImpl() { if (_client.State != LoginClientState.AuthedGG) { await _client.SendAsync(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed)); _client.Close(); return; } byte[] decrypt = DecryptPacket(); string username = Encoding.ASCII.GetString(decrypt, 0x5e, 14).Replace("\0", string.Empty); string password = Encoding.ASCII.GetString(decrypt, 0x6c, 16).Replace("\0", string.Empty); AccountContract account = await _accountService.GetAccountByLogin(username); if (account == null) { if (_config.ServerConfig.AutoCreate) { account = await _accountService.CreateAccount(username, password); } else { await _client.SendAsync(LoginFail.ToPacket(LoginFailReason.ReasonUserOrPassWrong)); _client.Close(); return; } } else { if (!await _accountService.CheckIfAccountIsCorrect(username, password)) { await _client.SendAsync(LoginFail.ToPacket(LoginFailReason.ReasonUserOrPassWrong)); _client.Close(); return; } if (LoginServer.ServiceProvider.GetService <ServerThreadPool>().LoggedAlready(account.AccountId)) { await _client.SendAsync(LoginFail.ToPacket(LoginFailReason.ReasonAccountInUse)); _client.Close(); return; } } _client.ActiveAccount = account; _client.State = LoginClientState.AuthedLogin; _client.SendAsync(LoginOk.ToPacket(_client)); }
static bool HandleAuthSession(LoginClient client, CMSG msgID, BinReader data) { data.BaseStream.Position += 8; string name = data.ReadString().ToLower(); if (name.Length < 3) { client.Close("Too short account name"); return(true); } if (client.Account != null) { client.Close(client.Account.Name + " tried to log in again as " + name); return(true); } BinWriter w = LoginClient.NewPacket(SMSG.AUTH_RESPONSE); if (LoginClient.IsAccountLoggedIn(name)) { w.Write((byte)0x19); client.Send(w); client.Close("Client tried to log in with an already logged in account."); return(true); } DBAccount account = null; try { account = (DBAccount)DataServer.Database.FindObjectByKey(typeof(DBAccount), name); } catch (WoWDaemon.Database.DatabaseException e) { client.Close(e.Message); return(true); } if (account == null) { account = new DBAccount(); account.Name = name; DataServer.Database.AddNewObject(account); Console.WriteLine("Created account: " + name); } client.Account = account; Console.WriteLine("Account " + name + " logged in from " + client.RemoteEndPoint); w.Write((byte)0x0C); client.Send(w); return(true); }
public void Close(int time) { if (_connection != null) { _connection.Close(true, time); } }
static void Main(string[] args) { HelloWorldService.HelloWorldClient ws = new HelloWorldService.HelloWorldClient(); Console.WriteLine(ws.DoWork()); Console.ReadLine(); ws.Close(); Login.LoginClient l = new LoginClient(); try { UserModel user = l.Authentication("pedroluisf", "aramis"); if (user == null) { Console.WriteLine("UserName / Password Inválidos"); Console.ReadLine(); } else { Console.WriteLine("Hello " + user.RealName); Console.ReadLine(); } l.Close(); } catch (Exception e) { Console.WriteLine(e.Message); Console.Read(); } }
public override void RunImpl() { if (_client.State != LoginClientState.AuthedLogin) { _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed)); _client.Close(); return; } if (!_client.Key.CheckLoginOKIdPair(_loginOkID1, _loginOkID2)) { _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed)); _client.Close(); return; } _client.Send(ServerList.ToPacket(_client)); }
public override void RunImpl() { if (_client.State != LoginClientState.AuthedLogin) { _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed)); _client.Close(); return; } if (_client.Key.LoginOkId1 != _loginOkID1 && _client.Key.LoginOkId2 != _loginOkID2) { _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed)); _client.Close(); return; } _client.Send(ServerList.ToPacket(_client)); }
static bool OnKick(LoginClient client, string input) { if (client.Account.AccessLvl < ACCESSLEVEL.GM) { Chat.System(client, "You do not have access to this command"); return(true); } string[] split = input.Split(' '); // if(split.Length == 3) // { // split[2] = split[2].TrimStart(' '); // } if (split.Length == 1) { return(false); } // { // split = input.Split(' '); // } string target = split[1]; DataObject[] objs = DataServer.Database.SelectObjects(typeof(DBCharacter), "Name = '" + target + "'"); if (objs.Length == 0) { Chat.System(client, "No such player."); return(true); } LoginClient targetClient = LoginServer.GetLoginClientByCharacterID(objs[0].ObjectId); if (targetClient == null || targetClient.Character == null) { Chat.System(client, "That player is not online."); return(true); } string tgtCharacter = targetClient.Character.Name; targetClient.Close(""); Chat.System(client, "Kick of " + tgtCharacter + " Successful!"); Console.WriteLine(tgtCharacter + " was kicked by " + client.Character.Name); //+"("+split[2]); // ScriptPacket pkg = new ScriptPacket(0x01); // pkg.Write(client.Character.ObjectId); // pkg.Write(creature.ObjectId); // pkg.Write(displayID); // pkg.Write(faction); // pkg.Write(script); // pkg.Write(level); // pkg.Write(health); // pkg.Write(mana); // client.WorldConnection.Send(pkg); return(true); }
public override async Task RunImpl() { if (_client.State != LoginClientState.AuthedLogin) { await _client.SendAsync(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed)); _client.Close(); return; } if (_client.Key.LoginOkId1 != _loginOkID1 || _client.Key.LoginOkId2 != _loginOkID2) { await _client.SendAsync(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed)); _client.Close(); return; } _client.SendAsync(ServerList.ToPacket(_client)); }
public override void RunImpl() { if (_client.State != LoginClientState.Connected) { _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed)); _client.Close(); return; } if (_sessionId == _client.SessionId) { _client.State = LoginClientState.AuthedGG; _client.Send(GGAuth.ToPacket(_client)); } else { _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed)); _client.Close(); } }
public override async Task RunImpl() { if (_client.State != LoginClientState.AuthedLogin) { await _client.SendAsync(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed)); _client.Close(); return; } if (_client.Key.LoginOkId1 != _loginOkID1 || _client.Key.LoginOkId2 != _loginOkID2) { await _client.SendAsync(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed)); _client.Close(); return; } L2Server server = LoginServer.ServiceProvider.GetService <ServerThreadPool>().Get(_serverId); if (server == null) { await _client.SendAsync(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed)); _client.Close(); return; } if (!server.Connected) { await _client.SendAsync(LoginFail.ToPacket(LoginFailReason.ReasonServerMaintenance)); _client.Close(); return; } await server.Thread.SendPlayer(_client); _client.SendAsync(PlayOk.ToPacket(_client)); }
static bool OnPlayerLogin(LoginClient client, CMSG msgID, BinReader data) { if (client.Character != null) { client.Close("Tried to login another character."); return(true); } uint id = data.ReadUInt32(); LoginServer.PlayerLogin(client, id); return(true); }
static bool OnPlayerLogin(LoginClient client, CMSG msgID, BinReader data) { if (client.Character != null) { client.Close("Tried to login another character."); return(true); } uint id = data.ReadUInt32(); Console.WriteLine("LoginClient:" + client.Account.Name + " CharID:" + id); LoginServer.PlayerLogin(client, id); return(true); }
public override async Task RunImpl() { await Task.Run(() => { if (_client.State != LoginClientState.Connected) { _client.SendAsync(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed)); _client.Close(); return; } if (_sessionId == _client.SessionId) { _client.State = LoginClientState.AuthedGG; _client.SendAsync(GGAuth.ToPacket(_client)); } else { _client.SendAsync(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed)); _client.Close(); } }); }
static bool LearnTalent(LoginClient client, CMSG msgID, BinReader data) { uint talentid = data.ReadUInt32(); DBTalents targetTalent = null; targetTalent = (DBTalents)DataServer.Database.FindObjectByKey(typeof(DBTalents), talentid); if (targetTalent == null) { Chat.System(client, "Talent " + talentid + " not found on DB"); return(true); } DBKnownTalents newTalent = null; try { newTalent = (DBKnownTalents)DataServer.Database.FindObjectByKey(typeof(DBKnownTalents), talentid); } catch (WoWDaemon.Database.DatabaseException e) { client.Close(e.Message); return(true); } if (newTalent == null) { newTalent = new DBKnownTalents(); newTalent.CharacterID = client.Character.ObjectId; newTalent.Talent_Id = talentid; newTalent.TalentLevel = 1; DataServer.Database.AddNewObject(newTalent); DataServer.Database.FillObjectRelations(client.Character); } else { newTalent.TalentLevel++; DataServer.Database.SaveObject(newTalent); } Chat.System(client, "Talent Learned: " + talentid); return(true); }
static bool HandleCharEnum(LoginClient client, CMSG msgID, BinReader data) { BinWriter w = LoginClient.NewPacket(SMSG.CHAR_ENUM); if (client.Account == null) { client.Close("HandleCharEnum: Not logged in."); return(true); } if (client.Account.Characters == null) { w.Write((byte)0); client.Send(w); return(true); } w.Write((byte)client.Account.Characters.Length); foreach (DBCharacter c in client.Account.Characters) { w.Write((ulong)c.ObjectId); w.Write(c.Name); w.Write((byte)c.Race); w.Write((byte)c.Class); w.Write(c.Gender); w.Write(c.Skin); w.Write(c.Face); w.Write(c.HairStyle); w.Write(c.HairColor); w.Write(c.FacialHairStyle); w.Write(c.Level); w.Write(c.Zone); w.Write(c.Continent); w.WriteVector(c.Position); w.Write(c.GuildID); w.Write(0); w.Write((byte)c.RestedState); w.Write(0); w.Write(0); w.Write(0); long pos = w.BaseStream.Position; w.Write(new byte[100]); if (c.Items != null) { foreach (DBItem item in c.Items) { if (item.OwnerSlot > 0x13) { continue; } if (item.Template == null) { Console.WriteLine("Database error: Item missing template object."); continue; } w.Set((int)(pos + item.OwnerSlot * 5), item.Template.DisplayID); w.Set((int)(pos + item.OwnerSlot * 5 + 4), (byte)item.Template.InvType); } } } client.Send(w); return(true); }
public override void RunImpl() { if (_client.State != LoginClientState.AuthedGG) { _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonAccessFailed)); _client.Close(); return; } var key = _client.RsaPair._privateKey; RSAEngine rsa = new RSAEngine(); rsa.init(false, key); byte[] decrypt = rsa.processBlock(Raw, 0, 128); if (decrypt.Length < 128) { byte[] temp = new byte[128]; Array.Copy(decrypt, 0, temp, 128 - decrypt.Length, decrypt.Length); decrypt = temp; } string username = Encoding.ASCII.GetString(decrypt, 0x5e, 14).Replace("\0", string.Empty); string password = Encoding.ASCII.GetString(decrypt, 0x6c, 16).Replace("\0", string.Empty); AccountContract account = _accountService.GetAccountByLogin(username); if (account == null) { if (_config.ServerConfig.AutoCreate) { account = _accountService.CreateAccount(username, L2Security.HashPassword(password)); } else { _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonUserOrPassWrong)); _client.Close(); return; } } else { if (!_accountService.CheckIfAccountIsCorrect(username, L2Security.HashPassword(password))) { _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonUserOrPassWrong)); _client.Close(); return; } if (LoginServer.ServiceProvider.GetService <ServerThreadPool>().LoggedAlready(username.ToLower())) { _client.Send(LoginFail.ToPacket(LoginFailReason.ReasonAccountInUse)); _client.Close(); return; } } _client.ActiveAccount = account; _client.State = LoginClientState.AuthedLogin; _client.Send(LoginOk.ToPacket(_client)); }
static bool OnBan(LoginClient client, string input) { if (client.Account.AccessLvl < ACCESSLEVEL.ADMIN) { Chat.System(client, "You do not have access to this command"); return(true); } string[] split = input.Split(' '); bool byAccount = false; switch (split.Length) { case 1: return(false); case 3: if (split[2].ToLower() == "account") { byAccount = true; } break; } string target = split[1]; string tgtIP = split[1]; LoginClient targetClient = null; DBAccount targetAccount = null; DBBanned targetIP; bool foundSomething = false; DBCharacter targetChar = (DBCharacter)DataServer.Database.FindObjectByKey(typeof(DBCharacter), target); if ((!byAccount) && (targetChar != null)) { //Found a character targetClient = LoginServer.GetLoginClientByCharacterID(targetChar.ObjectId); if (targetClient != null) { targetAccount = targetClient.Account; tgtIP = targetClient.RemoteEndPoint.ToString().Split(':')[0]; } else { DataObject[] objt = DataServer.Database.SelectObjects(typeof(DBAccount), "Account_ID = '" + targetChar.AccountID + "'"); if (objt.Length != 0) { targetAccount = (DBAccount)objt[0]; } foundSomething = true; } } else { targetAccount = (DBAccount)DataServer.Database.FindObjectByKey(typeof(DBAccount), target); } if (targetAccount != null) { if (targetAccount.AccessLvl == ACCESSLEVEL.BANNED) { Chat.System(client, " Account:" + targetAccount.Name + " is already banned"); } else if (client.Account.AccessLvl < targetAccount.AccessLvl) { Chat.System(client, "You cant ban someone with higher access than you fool!"); if (targetClient != null) { Chat.System(targetClient, client.Character.Name + " just tried to ban you!"); } Console.WriteLine(client.Character.Name + " attempted to Ban " + targetClient.Character.Name); return(true); } else { targetAccount.AccessLvl = ACCESSLEVEL.BANNED; targetAccount.Dirty = true; DataServer.Database.SaveObject(targetAccount); Chat.System(client, "Banning Account:" + targetAccount.Name); foundSomething = true; } if (targetClient == null) { tgtIP = targetAccount.LastIP; } else { targetClient.Close(""); } } // Chat.System(client,"TgtIP: >"+tgtIP+"<"); targetIP = (DBBanned)DataServer.Database.FindObjectByKey(typeof(DBBanned), tgtIP); if (targetIP != null) { Chat.System(client, "IP:" + tgtIP + " is already banned"); } else { targetIP = new DBBanned(); try { IPAddress tempIP = IPAddress.Parse(tgtIP); } catch (Exception) { } finally { targetIP.BanAddress = tgtIP; DateTime tmpDate = DateTime.Now; targetIP.BannedDate = tmpDate; targetIP.BannedBy = client.Account.Name; DataServer.Database.AddNewObject(targetIP); Chat.System(client, "Banning IP:" + tgtIP); Console.WriteLine("IP:" + tgtIP + " was banned by " + client.Account.Name); foundSomething = true; } } if (!foundSomething) { Chat.System(client, "Could not find anything to ban"); return(false); } Chat.System(client, "Done"); return(true); }
public void Disconnect(int accountId) { LoginClient client = _loggedClients.Select(x => x.Value).FirstOrDefault(x => x.ActiveAccount?.AccountId == accountId); client?.Close(); }
static bool HandleAuthSession(LoginClient client, CMSG msgID, BinReader data) { data.BaseStream.Position += 8; string name = data.ReadString().ToLower(); if (name.Length < 3) { client.Close("Too short account name"); return(true); } if (client.Account != null) { client.Close(client.Account.Name + " tried to log in again as " + name); return(true); } BinWriter w = LoginClient.NewPacket(SMSG.AUTH_RESPONSE); if (LoginClient.IsAccountLoggedIn(name)) { w.Write((byte)0x19); client.Send(w); client.Close("Client tried to log in with an already logged in account."); return(true); } DBAccount account = null; try { account = (DBAccount)DataServer.Database.FindObjectByKey(typeof(DBAccount), name); } catch (WoWDaemon.Database.DatabaseException e) { client.Close(e.Message); return(true); } if (account == null) { /*account = new DBAccount(); * account.Name = name; * account.Password = name; * DataServer.Database.AddNewObject(account); * Console.WriteLine("Created account: " + name);*/ w.Write((byte)0x1a); client.Send(w); client.Close("Invalid account"); return(true); } client.Account = account; if (client.Account.SessionKey == null) { w.Write((byte)0x1a); client.Send(w); client.Close("No SessionKey found"); return(true); } int c = 0; client.Hash = new byte[40]; string[] split = client.Account.SessionKey.Split('-'); foreach (string b in split) { client.Hash[c] = byte.Parse(b, System.Globalization.NumberStyles.HexNumber); c += 1; } client.Authenticated = true; Console.WriteLine("Account " + name + " logged in from " + client.RemoteEndPoint); w.Write((byte)0x0C); client.Send(w); return(true); }
static bool HandleCharDelete(LoginClient client, CMSG msgID, BinReader data) { uint id = data.ReadUInt32(); if (client.Account.Characters == null) { client.Close(client.Account.Name + " tried to delete a character when there was none on the account."); return(true); } foreach (DBCharacter c in client.Account.Characters) { if (id == c.ObjectId) { if (c.OnFriends != null) { foreach (DBFriendList Friend in c.OnFriends) { LoginClient FriendOnline = LoginServer.GetLoginClientByCharacterID(Friend.Owner_ID); if (FriendOnline != null) { BinWriter flist = LoginClient.NewPacket(SMSG.FRIEND_STATUS); Chat.System(FriendOnline, client.Character.Name + " is Online"); flist.Write((char)0x05); flist.Write((ulong)c.ObjectId); FriendOnline.Send(flist); try { DataServer.Database.DeleteObject(Friend); } catch (Exception e) { Console.WriteLine("Deleting Friend failed! " + e.Message); } FriendOnline.Character.Friends = null; DataServer.Database.FillObjectRelations(FriendOnline.Character); } else { try { DataServer.Database.DeleteObject(Friend); } catch (Exception) { Console.WriteLine("Deleting Friend failed!"); } } FriendOnline = null; } } try { DataServer.Database.DeleteObject(c); } catch (Exception e) { Console.WriteLine("Deleting character " + c.ObjectId + " failed! " + e.Message); } DBGuildMembers cMember = (DBGuildMembers)DataServer.Database.FindObjectByKey(typeof(DBGuild), c.ObjectId); if (cMember != null) { DBGuild guild = (DBGuild)DataServer.Database.FindObjectByKey(typeof(DBGuild), c.GuildID); DataServer.Database.DeleteObject(cMember); if (guild != null) { DataServer.Database.FillObjectRelations(guild); } } client.Account.Characters = null; DataServer.Database.FillObjectRelations(client.Account); BinWriter w = LoginClient.NewPacket(SMSG.CHAR_DELETE); w.Write((byte)0x36); client.Send(w); return(true); } } client.Close(client.Account.Name + " tried to delete a character that didn't belong to him."); return(true); }