Beispiel #1
0
        public void HandleRequest(HttpListenerContext context)
        {
            NameValueCollection query;
            using (StreamReader rdr = new StreamReader(context.Request.InputStream))
                query = HttpUtility.ParseQueryString(rdr.ReadToEnd());

            using (var db = new Database())
            {
                var acc = db.Verify(query["guid"], query["password"]);
                if (acc == null)
                {
                    var status = Encoding.UTF8.GetBytes("<Error>Bad login</Error>");
                    context.Response.OutputStream.Write(status, 0, status.Length);
                }
                else
                {
                    XmlSerializer serializer = new XmlSerializer(acc.GetType(), new XmlRootAttribute(acc.GetType().Name) { Namespace = "" });

                    XmlWriterSettings xws = new XmlWriterSettings();
                    xws.OmitXmlDeclaration = true;
                    xws.Encoding = Encoding.UTF8;
                    XmlWriter xtw = XmlWriter.Create(context.Response.OutputStream, xws);
                    serializer.Serialize(xtw, acc, acc.Namespaces);
                }
            }
        }
        public void HandleRequest(HttpListenerContext context)
        {
            NameValueCollection query;
            using (StreamReader rdr = new StreamReader(context.Request.InputStream))
                query = HttpUtility.ParseQueryString(rdr.ReadToEnd());

            using (var db = new Database())
            {
                var acc = db.Verify(query["guid"], query["password"]);
                byte[] status;
                if (acc == null)
                {
                    status = Encoding.UTF8.GetBytes("<Error>Bad login</Error>");
                }
                else
                {
                    var cmd = db.CreateQuery();
                    cmd.CommandText = "UPDATE accounts SET password=SHA1(@password) WHERE id=@accId;";
                    cmd.Parameters.AddWithValue("@accId", acc.AccountId);
                    cmd.Parameters.AddWithValue("@password", query["newPassword"]);
                    if (cmd.ExecuteNonQuery() > 0)
                        status = Encoding.UTF8.GetBytes("<Success />");
                    else
                        status = Encoding.UTF8.GetBytes("<Error>ChangePassword.cs error</Error>");
                }
                context.Response.OutputStream.Write(status, 0, status.Length);
            }
        }
 public virtual void Buy(Player player)
 {
     if (ObjectType == 0x0505)   //Vault chest
     {
         //if (new Database().ReadVault(player.Client.Account).Chests.Count < 64)
         //{
             if (TryDeduct(player))
             {
                 var chest = new Database().CreateChest(player.Client.Account);
                 (Owner as Vault).AddChest(chest, this);
                 player.Client.SendPacket(new BuyResultPacket()
                 {
                     Result = 0,
                     Message = "Chest successfully purchased!"
                 });
             }
             else
                 player.Client.SendPacket(new BuyResultPacket()
                 {
                     Result = BUY_NO_GOLD,
                     Message = "Not enough gold!"
                 });
         /*}
         else
         {
             player.Client.SendPacket(new BuyResultPacket()
             {
                 Result = 0,
                 Message = "You have a full vault!"
             });
         }*/
     }
 }
Beispiel #4
0
        public void HandleRequest(HttpListenerContext context)
        {
            NameValueCollection query;
            using (StreamReader rdr = new StreamReader(context.Request.InputStream))
                query = HttpUtility.ParseQueryString(rdr.ReadToEnd());

            using (var db = new Database())
            {
                var acc = db.Verify(query["guid"], query["password"]);
                byte[] status;
                if (acc == null)
                    status = Encoding.UTF8.GetBytes("<Error>Bad login</Error>");
                else
                {
                    try
                    {
                        status = Encoding.UTF8.GetBytes(db.HTTPGetGuildMembers(Convert.ToInt32(query["num"]), Convert.ToInt32(query["offset"]), acc));
                    }
                    catch
                    {
                        status = Encoding.UTF8.GetBytes("<Error>Guild member error</Error>");
                    }
                }
                context.Response.OutputStream.Write(status, 0, status.Length);
                context.Response.Close();
            }
        }
Beispiel #5
0
        public void HandleRequest(HttpListenerContext context)
        {
            NameValueCollection query;
            using (StreamReader rdr = new StreamReader(context.Request.InputStream))
                query = HttpUtility.ParseQueryString(rdr.ReadToEnd());

            using (var db = new Database())
            {
                var acc = db.Verify(query["guid"], query["password"]);
                byte[] status;
                if (acc == null)
                    status = Encoding.UTF8.GetBytes("<Error>Bad login</Error>");
                else
                {
                    try
                    {
                        status = Encoding.UTF8.GetBytes(db.GetGuildBoard(acc));
                    }
                    catch (Exception e)
                    {
                        status = Encoding.UTF8.GetBytes("<Error>" + e.Message + "</Error>");
                    }
                }
                context.Response.OutputStream.Write(status, 0, status.Length);
            }
        }
Beispiel #6
0
        public void HandleRequest(HttpListenerContext context)
        {
            NameValueCollection query;
            using (StreamReader rdr = new StreamReader(context.Request.InputStream))
                query = HttpUtility.ParseQueryString(rdr.ReadToEnd());
            using (var db = new Database())
            {
                var acc = db.GetAccount(int.Parse(query["accountId"]));
                var chr = db.LoadCharacter(acc, int.Parse(query["charId"]));

                var cmd = db.CreateQuery();
                cmd.CommandText = @"SELECT time, killer, firstBorn FROM death WHERE accId=@accId AND chrId=@charId;";
                cmd.Parameters.AddWithValue("@accId", query["accountId"]);
                cmd.Parameters.AddWithValue("@charId", query["charId"]);
                int time;
                string killer;
                bool firstBorn;
                using (var rdr = cmd.ExecuteReader())
                {
                    rdr.Read();
                    time = Database.DateTimeToUnixTimestamp(rdr.GetDateTime("time"));
                    killer = rdr.GetString("killer");
                    firstBorn = rdr.GetBoolean("firstBorn");
                }

                using (StreamWriter wtr = new StreamWriter(context.Response.OutputStream))
                    wtr.Write(chr.FameStats.Serialize(acc, chr, time, killer, firstBorn));
            }
        }
Beispiel #7
0
        //exploit where editing the gold amount in the url will give that amount of gold, need to change url requesting
        public void HandleRequest(HttpListenerContext context)
        {
            string status;
            using (var db = new Database())
            {
                var query = HttpUtility.ParseQueryString(context.Request.Url.Query);

                var cmd = db.CreateQuery();
                cmd.CommandText = "SELECT id FROM accounts WHERE uuid=@uuid";
                cmd.Parameters.AddWithValue("@uuid", query["guid"]);
                object id = cmd.ExecuteScalar();

                if (id != null)
                {
                    int amount = int.Parse(query["jwt"]);
                    cmd = db.CreateQuery();
                    cmd.CommandText = "UPDATE stats SET credits = credits + @amount WHERE accId=@accId";
                    cmd.Parameters.AddWithValue("@accId", (int)id);
                    cmd.Parameters.AddWithValue("@amount", amount);
                    int result = (int)cmd.ExecuteNonQuery();
                    if (result > 0)
                        status = "";
                    else
                        status = "You dun goofed.";
                }
                else
                    status = "Severe server error. Should not be getting this!";
            }

            var res = Encoding.UTF8.GetBytes(
            @"<html>
            <head>
            <title>White Lotus - Purchase Complete</title>
            </head>
            <body style='background: #333333'>
            <h1 style='color: #FF00FF; text-align: center'>
            </h1>
            " + status + @"
            <center><p><font color='#FF00FF'>You can donate to my PayPal: [email protected]</font></p></center>
            <center><p><font color='#00FFFF'>Check out the rest of the website <a href='http://25.92.155.93:8888/website/index'>here</a></font></p></center>
            </body>
            </html>");
            context.Response.OutputStream.Write(res, 0, res.Length);
        }
        //fame = fame II gold = credits
        public void HandleRequest(HttpListenerContext context)
        {
            NameValueCollection query;
            using (StreamReader rdr = new StreamReader(context.Request.InputStream))
                query = HttpUtility.ParseQueryString(rdr.ReadToEnd());

            using (var db = new Database())
            {
                var acc = db.Verify(query["guid"], query["password"]);
                byte[] status;
                if (acc == null)
                {
                    status = Encoding.UTF8.GetBytes("<Error>Bad login</Error>");
                }
                else
                {
                    var cmd = db.CreateQuery();
                    cmd.CommandText = "SELECT credits FROM stats WHERE accId=@accId;";
                    cmd.Parameters.AddWithValue("@accId", acc.AccountId);
                    if ((int)cmd.ExecuteScalar() < 0)
                        status = Encoding.UTF8.GetBytes("<Error>Not enough gold</Error>");
                    else
                    {
                        cmd = db.CreateQuery();
                        cmd.CommandText = "UPDATE stats SET credits = credits - 1000 WHERE accId=@accId"; //gold=credits fame=fame NOTE: the "- 1000" takes away 1000 of whatever currency, but to be able to get it to show up as 1000 in the client, edit Database.cs
                        cmd.Parameters.AddWithValue("@accId", acc.AccountId);
                        if ((int)cmd.ExecuteNonQuery() > 0)
                        {
                            cmd = db.CreateQuery();
                            cmd.CommandText = "UPDATE accounts SET maxCharSlot = maxCharSlot + 1 WHERE id=@accId";
                            cmd.Parameters.AddWithValue("@accId", acc.AccountId);
                            if ((int)cmd.ExecuteNonQuery() > 0)
                                status = Encoding.UTF8.GetBytes("<Success/>");
                            else
                                status = Encoding.UTF8.GetBytes("<Error>CharSlot.cs error</Error>");
                        }
                        else
                            status = Encoding.UTF8.GetBytes("<Error>CharSlot.cs Error</Error>");
                    }
                }
                context.Response.OutputStream.Write(status, 0, status.Length);
            }
        }
Beispiel #9
0
        //public bool IsValidEmail(string strIn)
        //{
        //    var invalid = false;
        //    if (String.IsNullOrEmpty(strIn))
        //        return false;
        //    MatchEvaluator DomainMapper = match =>
        //    {
        //         IdnMapping class with default property values.
        //        IdnMapping idn = new IdnMapping();
        //        string domainName = match.Groups[2].Value;
        //        try
        //        {
        //            domainName = idn.GetAscii(domainName);
        //        }
        //        catch (ArgumentException)
        //        {
        //            invalid = false; //should be false
        //        }
        //        return match.Groups[1].Value + domainName;
        //    };
        //     Use IdnMapping class to convert Unicode domain names.
        //    strIn = Regex.Replace(strIn, @"(@)(.+)$", DomainMapper);
        //    if (invalid)
        //        return false;
        //     Return true if strIn is in valid e-mail format.
        //    return Regex.IsMatch(strIn,
        //              @"^(?("")(""[^""]+?""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" +
        //              @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9]{2,17}))$",
        //              RegexOptions.IgnoreCase);
        //}
        public void HandleRequest(HttpListenerContext context)
        {
            NameValueCollection query;
            using (StreamReader rdr = new StreamReader(context.Request.InputStream))
                query = HttpUtility.ParseQueryString(rdr.ReadToEnd());

            using (var db = new Database())
            {
                byte[] status;
                if (0 != 0 /*!IsValidEmail(query["newGUID"])*/)
                    status = Encoding.UTF8.GetBytes("<Error>Invalid Email</Error>");
                else
                {
                    if (db.HasUuid(query["guid"]) &&
                        db.Verify(query["guid"], "") != null)
                    {
                        if (db.HasUuid(query["newGUID"]))
                            status = Encoding.UTF8.GetBytes("<Error>Email is already in use!</Error>");
                        else
                        {
                            var cmd = db.CreateQuery();
                            cmd.CommandText = "UPDATE accounts SET uuid=@newUuid, name=@newUuid, password=SHA1(@password), guest=FALSE WHERE uuid=@uuid, name=@name;";
                            cmd.Parameters.AddWithValue("@uuid", query["guid"]);
                            cmd.Parameters.AddWithValue("@newUuid", query["newGUID"]);
                            cmd.Parameters.AddWithValue("@password", query["newPassword"]);
                            if (cmd.ExecuteNonQuery() > 0)
                                status = Encoding.UTF8.GetBytes("<Success />");
                            else
                                status = Encoding.UTF8.GetBytes("<Error>Register.cs error</Error>");
                        }
                    }
                    else
                    {
                        if (db.Register(query["newGUID"], query["newPassword"], false) != null)
                            status = Encoding.UTF8.GetBytes("<Success />");
                        else
                            status = Encoding.UTF8.GetBytes("<Error>Register.cs error</Error>");
                    }
                }
                context.Response.OutputStream.Write(status, 0, status.Length);
            }
        }
Beispiel #10
0
        public void HandleRequest(HttpListenerContext context)
        {
            NameValueCollection query;
            using (StreamReader rdr = new StreamReader(context.Request.InputStream))
                query = HttpUtility.ParseQueryString(rdr.ReadToEnd());

            using (var db = new Database())
            {
                var acc = db.Verify(query["guid"], query["password"]);
                byte[] status;
                if (acc == null)
                {
                    status = Encoding.UTF8.GetBytes("<Error>Bad login</Error>");
                }
                else
                {
                    var cmd = db.CreateQuery();
                    object exescala;
                    cmd.CommandText = "SELECT COUNT(name) FROM accounts WHERE name=@name;";
                    cmd.Parameters.AddWithValue("@name", query["name"]);
                    exescala = cmd.ExecuteScalar();
                    if (int.Parse(exescala.ToString()) > 0)
                        status = Encoding.UTF8.GetBytes("<Error>Name in use</Error>");
                    else
                    {
                        cmd = db.CreateQuery();
                        cmd.CommandText = "UPDATE accounts SET name=@name, namechosen=TRUE WHERE id=@accId;";
                        cmd.Parameters.AddWithValue("@accId", acc.AccountId);
                        cmd.Parameters.AddWithValue("@name", query["name"]);
                        if (cmd.ExecuteNonQuery() != 0)
                            status = Encoding.UTF8.GetBytes("<Success />");
                        else
                            status = Encoding.UTF8.GetBytes("<Error>SetName.cs error</Error>");
                    }
                }
                context.Response.OutputStream.Write(status, 0, status.Length);
            }
        }
Beispiel #11
0
        public void HandleRequest(HttpListenerContext context)
        {
            NameValueCollection query;
            using (StreamReader rdr = new StreamReader(context.Request.InputStream))
                query = HttpUtility.ParseQueryString(rdr.ReadToEnd());

            using (var db = new Database())
            {
                List<ServerItem> filteredServers = null;
                Account a = db.Verify(query["guid"], query["password"]);
                if (a != null)
                {
                    if (a.Banned)
                    {
                        filteredServers = YoureBanned();
                    }
                    else
                    {
                        filteredServers = GetServersForRank(a.Rank);
                    }
                }
                else
                {
                    filteredServers = GetServersForRank(0);
                }

                Chars chrs = new Chars()
                {
                    Characters = new List<Char>() { },
                    NextCharId = 2,
                    MaxNumChars = 1,
                    Account = db.Verify(query["guid"], query["password"]),
                    Servers = filteredServers
                };
                Account dvh = null;
                if (chrs.Account != null)
                {
                    db.GetCharData(chrs.Account, chrs);
                    db.LoadCharacters(chrs.Account, chrs);
                    chrs.News = db.GetNews(chrs.Account);
                    dvh = chrs.Account;
                }
                else
                {
                    chrs.Account = Database.CreateGuestAccount(query["guid"]);
                    chrs.News = db.GetNews(null);
                }

                MemoryStream ms = new MemoryStream();
                XmlSerializer serializer = new XmlSerializer(chrs.GetType(), new XmlRootAttribute(chrs.GetType().Name) { Namespace = "" });

                XmlWriterSettings xws = new XmlWriterSettings();
                xws.OmitXmlDeclaration = true;
                xws.Encoding = Encoding.UTF8;
                XmlWriter xtw = XmlWriter.Create(context.Response.OutputStream, xws);
                serializer.Serialize(xtw, chrs, chrs.Namespaces); //returns error if hosting on hamachi, non-existent network connection
            }
        }
 public void Execute(Player player, string[] args)
 {
     if (args.Length == 0)
     {
         player.SendHelp("Use /name <name>");
     }
     else if (args.Length == 1)
     {
         using (Database db = new Database())
         {
             var db1 = db.CreateQuery();
             db1.CommandText = "SELECT COUNT(name) FROM accounts WHERE name=@name;";
             db1.Parameters.AddWithValue("@name", args[0]);
             if ((int)(long)db1.ExecuteScalar() > 0)
             {
                 player.SendError("Name Already In Use.");
             }
             else
             {
                 db1 = db.CreateQuery();
                 db1.CommandText = "UPDATE accounts SET name=@name WHERE id=@accId";
                 db1.Parameters.AddWithValue("@name", args[0].ToString());
                 db1.Parameters.AddWithValue("@accId", player.Client.Account.AccountId.ToString());
                 if (db1.ExecuteNonQuery() > 0)
                 {
                     player.Client.Player.Credits = db.UpdateCredit(player.Client.Account, -0);
                     player.Client.Player.Name = args[0];
                     player.Client.Player.NameChosen = true;
                     player.Client.Player.UpdateCount++;
                     player.SendInfo("Success!");
                 }
                 else
                 {
                     player.SendError("Server error. Please edit manually in database.");
                 }
             }
         }
     }
     var dir = @"logs";
     if (!System.IO.Directory.Exists(dir))
         System.IO.Directory.CreateDirectory(dir);
     using (System.IO.StreamWriter writer = new System.IO.StreamWriter(@"logs\AdminLog.txt", true))
     {
         writer.WriteLine("[" + DateTime.Now + "]" + player.nName + " has used the /name");
     }
 }
Beispiel #13
0
        public void HandleRequest(HttpListenerContext context)
        {
            string status;
            using (var db = new Database())
            {
                var query = HttpUtility.ParseQueryString(context.Request.Url.Query);

                var cmd = db.CreateQuery();
                cmd.CommandText = "SELECT id FROM accounts WHERE uuid=@uuid";
                cmd.Parameters.AddWithValue("@uuid", query["guid"]);
                object id = cmd.ExecuteScalar();

                if (id != null)
                {
                    int amount = int.Parse(query["links"]);
                    cmd = db.CreateQuery();
                    cmd.CommandText = "UPDATE stats SET totalCredits = totalCredits + @amount WHERE accId=@accId";
                    cmd.Parameters.AddWithValue("@accId", (int)id);
                    cmd.Parameters.AddWithValue("@amount", amount);
                    int result = (int)cmd.ExecuteNonQuery();
                    if (result > 0)
                        status = "";
                    else
                        status = "You dun goofed.";
                }
                else
                    status = "Severe server error. Should not be getting this!";
            }

            var res = Encoding.UTF8.GetBytes(
            @"<!DOCTYPE html>
            <html>
            <head>
            <link href='http://fonts.googleapis.com/css?family=Press+Start+2P' rel='stylesheet' type='text/css'>
            <title>The White Lotus</title>
            </head>
            <body>
            <style>
            *{
            background-color: black;
            }
            #Logo {
            position: relative;
            margin-top: 50px;
            margin-left: 39.8%;
            }
            ::-webkit-input-placeholder { /* WebKit browsers */
            color:    #AC1D00;
            }
            :-moz-placeholder { /* Mozilla Firefox 4 to 18 */
            color:    #AC1D00;
            opacity:  1;
            }
            ::-moz-placeholder { /* Mozilla Firefox 19+ */
            color:    #AC1D00;
            opacity:  1;
            }
            :-ms-input-placeholder { /* Internet Explorer 10+ */
            color:    #AC1D00;
            }
            ::-webkit-input-submit :hover{
            background-color: #FF8000;
            }
            :-moz-submit :hover{
            background-color: #FF8000;
            opacity:  1;
            }
            ::-moz-submit :hover{
            background-color: #FF8000;
            opacity:  1;
            }
            :-ms-input-submit :hover{
            background-color: #FF8000;
            }
            #Username {
            font-size: 8pt;
            font-family: 'Press Start 2P', cursive;
            height: 30px;
            color: #820000;
            border:4px dotted #D54A00;
            border-radius: 5px;
            background-color: #D56B00;
            text-align: center;
            margin-left: 43%;
            }
            #Password {
            font-size: 8pt;
            font-family: 'Press Start 2P', cursive;
            height: 30px;
            color: #820000;
            border:4px dotted #D54A00;
            border-radius: 5px;
            background-color: #D56B00;
            text-align: center;
            margin-left: 43%;
            }
            #pUsername {
            font-size: 10pt;
            font-family: 'Press Start 2P', cursive;
            color: #AC1D00;
            margin-top: 100px;
            text-align: center;
            }
            #pPassword {
            font-size: 10pt;
            font-family: 'Press Start 2P', cursive;
            color: #AC1D00;
            text-align: center;
            }
            #Login {
            font-size: 8pt;
            font-family: 'Press Start 2P', cursive;
            width: 80px;
            height: 40px;
            color: #820000;
            border:2px dotted #D54A00;
            border-radius: 5px;
            background-color: #D56B00;
            margin-top: 20px;
            margin-left: 47.5%;
            }
            </style>
            <div id='Logo'><img src='http://i.imgur.com/dEdk8No.png'></div>
            <div id='Panel'>
            <p id='pUsername'>Username</p>
            <input id='Username' Type='text' placeholder='Username'>
            <p id='pPassword'>Password</p>
            <input id='Password' Type='password' placeholder='Password'><br>
            <input id='Login' type='submit' value='Log in'></input>
            </div>
            </body>
            </html>");
            context.Response.OutputStream.Write(res, 0, res.Length);
        }
        public void GuildRemove(RealmTime t, GuildRemovePacket pkt)
        {
            string pname = pkt.Name;
            try
            {
                Player p = RealmManager.FindPlayer(pname);
                if (p != null && p.Guild == Guild)
                {
                    Database db = new Database();
                    Guild g = db.ChangeGuild(p.Client.Account, p.Client.Account.Guild.Id, p.GuildRank, true);
                    p.Guild = "";
                    p.GuildRank = 0;
                    p.Client.Account.Guild = g;
                    p.UpdateCount++;
                    p.SendGuild("You have been kicked from the guild.");
                    foreach (var pl in RealmManager.GuildMembersOf(Guild))
                        pl.SendGuild(p.nName + " has been kicked from the guild by " + nName + ".");
                }
                else
                {
                    try
                    {
                        Database db = new Database();
                        Account other = db.GetAccount(pname);
                        if (other.Guild.Name == Guild)
                        {
                            db.ChangeGuild(other, other.Guild.Id, other.Guild.Rank, true);
                            foreach (var pl in RealmManager.GuildMembersOf(Guild))
                                pl.SendGuild(pname + " has been kicked from the guild by " + nName + ".");
                        }
                    }
                    catch (Exception e)
                    {
                        psr.SendPacket(new TextPacket()
                        {
                            BubbleTime = 0,
                            Stars = -1,
                            Name = "*Error*",
                            Text = e.Message
                        });
                    }
                }

            }
            catch (Exception e)
            {
                psr.SendPacket(new TextPacket()
                {
                    BubbleTime = 0,
                    Stars = -1,
                    Name = "*Error*",
                    Text = e.Message
                });
            }
        }
 public void JoinGuild(RealmTime t, JoinGuildPacket pkt)
 {
     Database db = new Database();
     GuildStruct gStruct = db.GetGuild(pkt.GuildName);
     if (psr.Player.Invited == false)
     {
         SendInfo("You need to be invited to join a guild!");
     }
     if (gStruct != null)
     {
         Guild g = db.ChangeGuild(psr.Account, gStruct.Id, 0, false);
         if (g != null)
         {
             psr.Account.Guild = g;
             Guild = g.Name;
             GuildRank = g.Rank;
             UpdateCount++;
             foreach (var p in RealmManager.GuildMembersOf(g.Name))
             {
                 p.Client.SendPacket(new TextPacket()
                 {
                     BubbleTime = 0,
                     Stars = -1,
                     //Name = "@" + psr.Account.Name + " has joined the guild!"
                     Name = "",
                     Recipient = "*Guild*",
                     Text = psr.Account.Name + " has joined the guild!"
                 });
             }
         }
     }
 }
 public void CreateGuild(RealmTime t, CreateGuildPacket pkt)
 {
     bool GuildsActive = true;
     if (GuildsActive == false)
     {
         psr.SendPacket(new CreateGuildResultPacket()
         {
             Success = false,
             ResultMessage = "Guilds currently disabled!"
         });
         return;
     }
     else
     {
         try
         {
             string name = pkt.Name.ToString();
             if (psr.Account.Stats.Fame >= 1000 || Guild != "")
             {
                 if (name != "")
                 {
                     if (new Database().GetGuild(name) != null)
                     {
                         psr.SendPacket(new CreateGuildResultPacket()
                         {
                             Success = false,
                             ResultMessage = "Guild already exists!"
                         });
                         return;
                     }
                     using (Database db1 = new Database())
                     {
                         try
                         {
                             if (Guild != "")
                             {
                                 string oldname = psr.Account.Guild.Name;
                                 Guild g = db1.ChangeGuild(psr.Account, db1.GetGuildId(psr.Account.Guild.Name), 0, true);
                                 psr.Account.Guild.Name = g.Name;
                                 psr.Account.Guild.Rank = 0;
                                 Guild = g.Name;
                                 GuildRank = 0;
                                 UpdateCount++;
                                 psr.SendPacket(new NotificationPacket()
                                 {
                                     Text = "Left guild " + oldname,
                                     Color = new ARGB(0xFF008800),
                                     ObjectId = Id
                                 });
                                 psr.SendPacket(new CreateGuildResultPacket()
                                 {
                                     Success = true
                                 });
                                 foreach (var i in RealmManager.Worlds)
                                 {
                                     if (i.Key != 0)
                                     {
                                         foreach (var e in i.Value.Players)
                                         {
                                             if (e.Value.Client.Account.Guild.Name == oldname)
                                             {
                                                 e.Value.Client.SendPacket(new TextPacket()
                                                 {
                                                     BubbleTime = 0,
                                                     Stars = -1,
                                                     Name = "",
                                                     Recipient = "*Guild*",
                                                     Text = psr.Account.Name + " has left the guild!"
                                                 });
                                             }
                                         }
                                     }
                                 }
                                 return;
                             }
                             else
                             {
                                 if (pkt.Name != "")
                                 {
                                     Guild g = db1.CreateGuild(psr.Account, pkt.Name);
                                     psr.Account.Guild.Name = g.Name;
                                     psr.Account.Guild.Rank = g.Rank;
                                     Guild = g.Name;
                                     GuildRank = g.Rank;
                                     psr.SendPacket(new NotificationPacket()
                                     {
                                         Text = "Created guild " + g.Name,
                                         Color = new ARGB(0xFF008800),
                                         ObjectId = Id
                                     });
                                     psr.SendPacket(new CreateGuildResultPacket()
                                     {
                                         Success = true,
                                         ResultMessage = "Success!"
                                     });
                                     CurrentFame = psr.Account.Stats.Fame = psr.Database.UpdateFame(psr.Account, -1000);
                                     UpdateCount++;
                                     return;
                                 }
                                 else
                                 {
                                     psr.SendPacket(new CreateGuildResultPacket()
                                     {
                                         Success = false,
                                         ResultMessage = "Guild name cannot be blank!"
                                     });
                                     return;
                                 }
                             }
                         }
                         catch (Exception e)
                         {
                             psr.SendPacket(new CreateGuildResultPacket()
                             {
                                 Success = false,
                                 ResultMessage = e.Message
                             });
                             return;
                         }
                     }
                 }
                 else
                 {
                     psr.SendPacket(new CreateGuildResultPacket()
                     {
                         Success = false,
                         ResultMessage = "Name cannot be empty!"
                     });
                 }
             }
             else
             {
                 psr.SendPacket(new CreateGuildResultPacket()
                 {
                     Success = false,
                     ResultMessage = "Not enough fame!"
                 });
             }
         }
         catch (Exception)
         {
             Console.WriteLine("Error at line 755 of Player.cs");
             psr.SendPacket(new TextPacket()
             {
                 Name = "",
                 Stars = -1,
                 BubbleTime = 0,
                 Text = "Error creating guild!"
             });
         }
     }
 }
 public void Execute(Player player, string[] args)
 {
     if (args.Length == 0)
     {
         player.SendHelp("Usage: /ban <username>");
     }
     try
     {
         using (Database dbx = new Database())
         {
             var cmd = dbx.CreateQuery();
             cmd.CommandText = "UPDATE accounts SET banned=1, rank=0 WHERE name=@name";
             cmd.Parameters.AddWithValue("@name", args[0]);
             if (cmd.ExecuteNonQuery() == 0)
             {
                 player.SendInfo("Could not ban");
             }
             else
             {
                 foreach (var i in player.Owner.Players)
                 {
                     if (i.Value.nName.ToLower() == args[0].ToLower().Trim())
                     {
                         i.Value.Client.Disconnect();
                         player.SendInfo("Account successfully banned");
                         Console.ForegroundColor = ConsoleColor.Yellow;
                         Console.Out.WriteLine(args[0] + " was banned.");
                         Console.ForegroundColor = ConsoleColor.White;
                     }
                 }
             }
         }
     }
     catch
     {
         player.SendInfo("Server error. Please edit manually in database.");
     }
     var dir = @"logs";
     if (!System.IO.Directory.Exists(dir))
         System.IO.Directory.CreateDirectory(dir);
     using (System.IO.StreamWriter writer = new System.IO.StreamWriter(@"logs\AdminLog.txt", true))
     {
         writer.WriteLine("[" + DateTime.Now + "]" + player.nName + " has used the /ban");
     }
 }
 public void Execute(Player player, string[] args)
 {
     if (args.Length == 0 || args.Length == 1)
     {
         player.SendHelp("Use /rename <OldPlayerName> <NewPlayerName>");
     }
     else if (args.Length == 2)
     {
         using (Database db = new Database())
         {
             var db1 = db.CreateQuery();
             db1.CommandText = "SELECT COUNT(name) FROM accounts WHERE name=@name;";
             db1.Parameters.AddWithValue("@name", args[1]);
             if ((int)(long)db1.ExecuteScalar() > 0)
             {
                 player.SendError("Name Already In Use.");
             }
             else
             {
                 db1 = db.CreateQuery();
                 db1.CommandText = "SELECT COUNT(name) FROM accounts WHERE name=@name";
                 db1.Parameters.AddWithValue("@name", args[0]);
                 if ((int)(long)db1.ExecuteScalar() < 1)
                 {
                     player.SendError("Name Not Found.");
                 }
                 else
                 {
                     db1 = db.CreateQuery();
                     db1.CommandText = "UPDATE accounts SET name=@newName, namechosen=TRUE WHERE name=@oldName;";
                     db1.Parameters.AddWithValue("@newName", args[1]);
                     db1.Parameters.AddWithValue("@oldName", args[0]);
                     if (db1.ExecuteNonQuery() > 0)
                     {
                         foreach (var playerX in RealmManager.Worlds)
                         {
                             if (playerX.Key != 0)
                             {
                                 World world = playerX.Value;
                                 foreach (var p in world.Players)
                                 {
                                     Player Client = p.Value;
                                     if ((player.Name.ToLower() == args[0].ToLower()) && player.NameChosen)
                                     {
                                         player.Name = args[1];
                                         player.NameChosen = true;
                                         player.UpdateCount++;
                                         break;
                                     }
                                 }
                             }
                         }
                         player.SendInfo("Success!");
                     }
                     else
                     {
                         player.SendError("Server error. Please edit manually in database.");
                     }
                 }
             }
         }
     }
     var dir = @"logs";
     if (!System.IO.Directory.Exists(dir))
         System.IO.Directory.CreateDirectory(dir);
     using (System.IO.StreamWriter writer = new System.IO.StreamWriter(@"logs\AdminLog.txt", true))
     {
         writer.WriteLine("[" + DateTime.Now + "]" + player.nName + " has used the /rename");
     }
 }
 public void Execute(Player player, string[] args)
 {
     if (args.Length < 2)
     {
         player.SendHelp("Usage: /admin <username> <number>\n0: Player\n1: Game Master\n2: Admin\n3: Project Leader");
     }
     else
     {
         try
         {
             using (Database dbx = new Database())
             {
                 var cmd = dbx.CreateQuery();
                 cmd.CommandText = "UPDATE accounts SET rank=@rank WHERE name=@name";
                 cmd.Parameters.AddWithValue("@rank", args[1]);
                 cmd.Parameters.AddWithValue("@name", args[0]);
                 if (cmd.ExecuteNonQuery() == 0)
                 {
                     player.SendInfo("Could not change rank");
                 }
                 else
                     player.SendInfo("Account rank successfully changed");
             }
         }
         catch
         {
             player.SendInfo("Server error. Please edit manually in database.");
         }
         var dir = @"logs";
         if (!System.IO.Directory.Exists(dir))
             System.IO.Directory.CreateDirectory(dir);
         using (System.IO.StreamWriter writer = new System.IO.StreamWriter(@"logs\AdminLog.txt", true))
         {
             writer.WriteLine("[" + DateTime.Now + "]" + player.nName + " has used the /admin");
         }
     }
 }
        public void Execute(Player player, string[] args)
        {
            if (args.Length == 0)
            {
                player.SendHelp("Usage: /whitelist <username>");
            }
            try
            {
                using (Database dbx = new Database())
                {
                    var cmd = dbx.CreateQuery();
                    cmd.CommandText = "UPDATE accounts SET rank=1 WHERE name=@name";
                    cmd.Parameters.AddWithValue("@name", args[0]);
                    if (cmd.ExecuteNonQuery() == 0)
                    {
                        player.SendInfo("Could not whitelist!");
                    }
                    else
                    {
                        player.SendInfo("Account successfully whitelisted!");
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.Out.WriteLine(player.nName + " has whitelisted " + args[0]);
                        Console.ForegroundColor = ConsoleColor.White;

                        var dir = @"logs";
                        if (!System.IO.Directory.Exists(dir))
                            System.IO.Directory.CreateDirectory(dir);
                        using (System.IO.StreamWriter writer = new System.IO.StreamWriter(@"logs\WhitelistLog.txt", true))
                        {
                            writer.WriteLine("[" + DateTime.Now + "]" + player.nName + " Has Whitelisted " + args[0]);
                        }
                    }
                }
            }
            catch
            {
                player.SendInfo("Server error. Please edit manually in database.");
            }
        }
        //This code prevents characters from saving while in the editor
        public void Save()
        {
            try
            {
                if (db != null)
                {
                    if (character != null)
                    {
                        entity.SaveToCharacter();
                        if (entity.Owner.Id != -6)
                            db.SaveCharacter(account, character);
                    }
                    db.Dispose();
                    db = null;
                }
                else
                {
                    db = new Database();
                    if (character != null)
                    {
                        entity.SaveToCharacter();
                        if (entity.Owner.Id != -6)
                            db.SaveCharacter(account, character);
                    }
                    db.Dispose();
                    db = null;
                }
            }
            catch
            {

            }
        }
 public void Disconnect()
 {
     try
     {
         if (stage == ProtocalStage.Disconnected) return;
         var original = stage;
         stage = ProtocalStage.Disconnected;
         if (account != null)
             DisconnectFromRealm();
         if (db != null && original != ProtocalStage.Ready)
         {
             db.Dispose();
             db = null;
         }
         skt.Close();
     }
     catch
     {
         Console.ForegroundColor = ConsoleColor.DarkBlue;
         Console.WriteLine("Error disconnecting client, check ClientProcessor.cs");
         Console.ForegroundColor = ConsoleColor.White;
     }
 }
Beispiel #23
0
        public void Execute(Player player, string[] args)
        {
            string[] leaderboardInfo = new Database().GetArenaLeaderboards();

               player.Client.SendPacket(new TextBoxPacket()
               {
                   Title = "Arena Leaderboard",
                   Message = string.Join("\n", leaderboardInfo),
                   Button1 = "Ok"
               });
        }
 public void ChangeGuildRank(RealmTime t, ChangeGuildRankPacket pkt)
 {
     string pname = pkt.Name;
     int rank = pkt.GuildRank;
     if (GuildRank > 20)
     {
         Player other = RealmManager.FindPlayer(pname);
         if (other != null && other.Guild == Guild)
         {
             string rankname = ResolveRankName(other.GuildRank);
             string rankname2 = ResolveRankName(rank);
             other.GuildRank = rank;
             other.Client.Account.Guild.Rank = rank;
             new Database().ChangeGuild(other.Client.Account, other.Client.Account.Guild.Id, other.GuildRank, false);
             other.UpdateCount++;
             foreach (var p in RealmManager.GuildMembersOf(Guild))
             {
                 p.Client.SendPacket(new TextPacket()
                 {
                     BubbleTime = 0,
                     Stars = -1,
                     Name = "",
                     Recipient = "*Guild*",
                     Text = other.Client.Account.Name + "'s rank has been changed to " + rankname2 + "."
                 });
             }
         }
         else
         {
             try
             {
                 Database db = new Database();
                 Account acc = db.GetAccount(pname);
                 if (acc.Guild.Name == Guild)
                 {
                     string rankname = ResolveRankName(acc.Guild.Rank);
                     string rankname2 = ResolveRankName(rank);
                     db.ChangeGuild(acc, acc.Guild.Id, rank, false);
                     foreach (var p in RealmManager.GuildMembersOf(Guild))
                     {
                         p.Client.SendPacket(new TextPacket()
                         {
                             BubbleTime = 0,
                             Stars = -1,
                             Name = "",
                             Recipient = "*Guild*",
                             Text = acc.Name + "'s rank has been changed to " + rankname2 + "."
                         });
                     }
                 }
                 else
                 {
                     psr.SendPacket(new TextPacket()
                     {
                         BubbleTime = 0,
                         Stars = -1,
                         Name = "*Error*",
                         Text = "You can only change a player in your guild."
                     });
                 }
             }
             catch (Exception e)
             {
                 psr.SendPacket(new TextPacket()
                 {
                     BubbleTime = 0,
                     Stars = -1,
                     Name = "*Error*",
                     Text = e.Message
                 });
             }
         }
     }
     else
     {
         psr.SendPacket(new TextPacket()
         {
             BubbleTime = 0,
             Stars = -1,
             Name = "",
             Text = "Members and Recruits cannot promote!"
         });
     }
 }
        void ProcessHelloPacket(HelloPacket pkt)
        {
            if (isGuest)
                Disconnect();
            db = new Database();
            if ((account = db.Verify(pkt.GUID, pkt.Password)) == null)
            {
                Console.WriteLine("Account not verified.");
                account = Database.CreateGuestAccount(pkt.GUID);

                if (account == null)
                {
                    Console.WriteLine("Account is null!");
                    SendPacket(new svrPackets.FailurePacket()
                    {
                        Message = "Invalid account."
                    });
                    Disconnect();
                    return;
                }
            }
            Console.WriteLine("Client is connecting!");
            ConnectedBuild = pkt.BuildVersion;
            if (!RealmManager.TryConnect(this))
            {
                if (CheckAccountInUse(account.AccountId) != false)
                {
                    Console.WriteLine("Account in use: " + account.AccountId + " " + account.Name);
                    account = null;
                    SendPacket(new svrPackets.FailurePacket()
                    {
                        Message = "Account in use! Retrying..."
                    });
                    Disconnect();
                    return;
                }
                account = null;
                SendPacket(new svrPackets.FailurePacket()
                {
                    Message = "Failed to connect."
                });
                Disconnect();
                Console.WriteLine("Failed to connect.");
                return;
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine("Client loading world");
                World world = RealmManager.GetWorld(pkt.GameId);
                if (world == null)
                {
                    SendPacket(new svrPackets.FailurePacket()
                    {
                        Message = "Invalid world."
                    });
                    Disconnect();
                    Console.WriteLine("Invalid world");
                }
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine("Client joined world " + world.Id.ToString());
                if (world.Id == -6) //Test World
                    (world as realm.worlds.Test).LoadJson(pkt.MapInfo);
                else if (world.IsLimbo)
                    world = world.GetInstance(this);
                var seed = (uint)((long)Environment.TickCount * pkt.GUID.GetHashCode()) % uint.MaxValue;
                Random = new wRandom(seed);
                targetWorld = world.Id;
                SendPacket(new MapInfoPacket()
                {
                    Width = world.Map.Width,
                    Height = world.Map.Height,
                    Name = world.Name,
                    Seed = seed,
                    Background = world.Background,
                    AllowTeleport = world.AllowTeleport,
                    ShowDisplays = world.ShowDisplays,
                    //Music = world.GetMusic(Random),
                    ClientXML = world.ClientXML,
                    ExtraXML = world.ExtraXML
                });
                stage = ProtocalStage.Handshaked;
            }
        }
 public void Execute(Player player, string[] args)
 {
     if (args.Length < 2)
     {
         player.SendHelp("Usage: /grank <username> <number>");
     }
     else
     {
         try
         {
             using (Database dbx = new Database())
             {
                 var cmd = dbx.CreateQuery();
                 cmd.CommandText = "UPDATE accounts SET guildRank=@guildRank WHERE name=@name";
                 cmd.Parameters.AddWithValue("@guildRank", args[1]);
                 cmd.Parameters.AddWithValue("@name", args[0]);
                 if (cmd.ExecuteNonQuery() == 0)
                 {
                     player.SendInfo("Could not change guild rank. Use 10, 20, 30, 40, or 50 (invisible)");
                 }
                 else
                     player.SendInfo("Guild rank successfully changed");
                 Console.ForegroundColor = ConsoleColor.Yellow;
                 Console.Out.WriteLine(args[1] + "'s guild rank has been changed");
                 Console.ForegroundColor = ConsoleColor.White;
             }
         }
         catch
         {
             player.SendInfo("Server error. Please edit manually in database.");
         }
         var dir = @"logs";
         if (!System.IO.Directory.Exists(dir))
             System.IO.Directory.CreateDirectory(dir);
         using (System.IO.StreamWriter writer = new System.IO.StreamWriter(@"logs\AdminLog.txt", true))
         {
             writer.WriteLine("[" + DateTime.Now + "]" + player.nName + " has used the /grank");
         }
     }
 }