private void MsgHandler_Login(Client client, ClientPacket msg) { var name = msg.ReadString(msg.ReadByte()); var password1 = msg.ReadString(msg.ReadByte()); var accountid = 0; var password2 = String.Empty; var gamemaster = AdminRights.None; var active = false; var exists = false; var com = Program.MySqlConnection.CreateCommand(); com.CommandText = "SELECT characters.acct_id, characters.password, characters.gm, accounts.active " + "FROM characters " + "LEFT JOIN accounts " + "ON characters.acct_id = accounts.acct_id " + "WHERE (characters.name = @name) AND (characters.server = @server)"; com.Parameters.AddWithValue("@name", name); com.Parameters.AddWithValue("@server", GameServer.Name); var reader = com.ExecuteReader(); if (reader.Read()) { accountid = reader.GetInt32(0); password2 = reader.GetString(1); gamemaster = (AdminRights)Enum.Parse(typeof(AdminRights), reader.GetString(2)); active = (!reader.IsDBNull(3) && reader.GetBoolean(3)); exists = true; } reader.Close(); if (!GameServer.AllowLogin) { client.SendLoginMessage(14, "The game server is currently closed."); return; } if (!exists) { client.SendLoginMessage(14, "That character does not exist."); return; } if (password1 != password2) { client.SendLoginMessage(14, "Incorrect password."); return; } if (accountid == 0) { client.SendLoginMessage(14, "Please register your character at game.wewladh.com"); return; } if (!active) { client.SendLoginMessage(14, "Your account has been locked."); return; } foreach (Client c in GameServer.Clients) { if ((c.Player != null) && c.Player.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase)) { c.Connected = false; client.SendLoginMessage(14, "Your character is already playing."); return; } if ((c.Player != null) && (accountid != 0) && (c.Player.AccountID == accountid)) { c.Connected = false; client.SendLoginMessage(14, "Your account is already playing."); return; } } if (Program.RunningSlowly) { client.SendLoginMessage(14, "The game server is busy right now. Please try again."); return; } client.SendLoginMessage(0, "\0"); var p = new ServerPacket(0x22); p.WriteByte(0x00); client.Enqueue(p); foreach (var message in File.ReadAllLines(GameServer.DataPath + "\\login.txt")) { client.SendMessage(message); } var r = new Redirection(); r.DestinationServer = GameServer; r.EncryptionParameters = client.EncryptionParams; r.Name = name; r.SourceServer = this; client.Redirect(r); }
private void MsgHandler_Logoff(Client client, ClientPacket msg) { }
private void MsgHandler_CreateB(Client client, ClientPacket msg) { if (string.IsNullOrEmpty(client.NewPlayerName) || string.IsNullOrEmpty(client.NewPlayerPassword)) { return; } var com = Program.MySqlConnection.CreateCommand(); com.CommandText = "SELECT COUNT(*) FROM characters WHERE (name = @name) AND (server = @server)"; com.Parameters.AddWithValue("@name", client.NewPlayerName); com.Parameters.AddWithValue("@server", GameServer.Name); var result = com.ExecuteScalar(); if ((long)result > 0) { client.SendLoginMessage(3, "That character already exists."); return; } Player p = Player.Create(GameServer, client.NewPlayerName); com = Program.MySqlConnection.CreateCommand(); com.CommandText = "INSERT INTO characters VALUES (0, @name, @password, 0, @server, @creation_date, 0, " + "'None', 'None', 'Peasant', 'None', 0, 0, 0, 0, 'North', 0, 0, 0, 0, 0, 0, " + "0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '', 0, 0, 'None', '', '')"; // 50 com.Parameters.AddWithValue("@name", client.NewPlayerName); com.Parameters.AddWithValue("@password", client.NewPlayerPassword); com.Parameters.AddWithValue("@server", GameServer.Name); com.Parameters.AddWithValue("@creation_date", DateTime.UtcNow); com.ExecuteNonQuery(); com = Program.MySqlConnection.CreateCommand(); com.CommandText = "SELECT character_id FROM characters WHERE (name = @name) AND (server = @server)"; com.Parameters.AddWithValue("@name", p.Name); com.Parameters.AddWithValue("@server", GameServer.Name); result = com.ExecuteScalar(); p.GUID = (int)result; p.HairStyle = msg.ReadByte(); p.Sex = (Gender)msg.ReadByte(); p.HairColor = msg.ReadUInt16(); if ((p.HairStyle > 17) || (p.HairStyle < 1)) { p.HairStyle = 1; } if ((p.Sex != Gender.Male) && (p.Sex != Gender.Female)) { p.Sex = Gender.Male; } if (p.HairColor > 13) { p.HairColor = 0; } p.Loaded = true; p.Save(); client.NewPlayerName = null; client.NewPlayerPassword = null; client.SendLoginMessage(0, "\0"); Program.WriteLine("New character created: {0}", p.Name); }