Example #1
0
        /// <summary>
        /// Handles a player leave notification
        /// </summary>
        static public void Handle_CS_PlayerLeave(CS_PlayerLeave <Zone> pkt, Zone zone)
        {               //He's gone!
            if (zone == null)
            {
                Log.write(TLog.Error, "Handle_CS_PlayerLeave(): Called with null zone.");
                return;
            }
            if (string.IsNullOrWhiteSpace(pkt.alias))
            {
                Log.write(TLog.Warning, "Handle_CS_PlayerLeave(): No alias provided.");
            }

            Zone.Player p = zone.getPlayer(pkt.alias);
            if (p == null)
            {
                Log.write(TLog.Warning, "Handle_CS_PlayerLeave(): Player '{0}' not found by alias.", pkt.alias);
                //Don't return until I have a better grasp of this
            }

            //Remove the player from the zone
            zone.lostPlayer(pkt.player.id);

            Log.write("Player '{0}' left zone '{1}'", pkt.alias, zone._zone.name);

            // Update their playtime
            using (InfantryDataContext db = zone._server.getContext())
            {
                Data.DB.alias alias = db.alias.SingleOrDefault(a => a.name.Equals(pkt.alias));
                //Data.DB.alias alias = db.alias.SingleOrDefault(a => a.id == p.aliasid);
                //If person was loaded correctly, save their info
                if (alias != null)
                {
                    TimeSpan ts      = DateTime.Now - alias.lastAccess;
                    Int64    minutes = ts.Minutes;
                    alias.timeplayed += minutes;

                    db.SubmitChanges();
                }
            }
        }
Example #2
0
        /// <summary>
        /// Handles the zone login request packet
        /// </summary>
        static public void Handle_CS_PlayerLogin(CS_PlayerLogin <Zone> pkt, Zone zone)
        {       //Make a note
            Log.write(TLog.Inane, "Player login request for '{0}' on '{1}'", pkt.alias, zone);

            SC_PlayerLogin <Zone> plog = new SC_PlayerLogin <Zone>();

            plog.player = pkt.player;

            if (String.IsNullOrWhiteSpace(pkt.alias))
            {
                plog.bSuccess     = false;
                plog.loginMessage = "Please enter an alias.";

                zone._client.send(plog);
                return;
            }
            //Are they using the launcher?
            if (String.IsNullOrWhiteSpace(pkt.ticketid))
            {   //They're trying to trick us, jim!
                plog.bSuccess     = false;
                plog.loginMessage = "Please use the Infantry launcher to run the game.";

                zone._client.send(plog);
                return;
            }
            if (pkt.ticketid.Contains(':'))
            {   //They're using the old, outdated launcher
                plog.bSuccess     = false;
                plog.loginMessage = "Please use the updated launcher from the website.";

                zone._client.send(plog);
                return;
            }


            using (InfantryDataContext db = zone._server.getContext())
            {
                Data.DB.player  player  = null;
                Data.DB.account account = db.accounts.SingleOrDefault(acct => acct.ticket.Equals(pkt.ticketid));

                if (account == null)
                {       //They're trying to trick us, jim!
                    plog.bSuccess     = false;
                    plog.loginMessage = "Your session id has expired. Please re-login.";

                    zone._client.send(plog);
                    return;
                }

                //Is there already a player online under this account?
                if (!DBServer.bAllowMulticlienting && zone._server._zones.Any(z => z.hasAccountPlayer(account.id)))
                {
                    plog.bSuccess     = false;
                    plog.loginMessage = "Account is currently in use.";

                    zone._client.send(plog);
                    return;
                }

                //Check for IP and UID bans
                Logic_Bans.Ban banned = Logic_Bans.checkBan(pkt, db, account, zone._zone.id);

                if (banned.type == Logic_Bans.Ban.BanType.GlobalBan)
                {   //We don't respond to globally banned player requests
                    plog.bSuccess     = false;
                    plog.loginMessage = "Banned.";

                    Log.write(TLog.Warning, "Failed login: "******" Alias: " + pkt.alias + " Reason: " + banned.type.ToString());
                    zone._client.send(plog);
                    return;
                }

                if (banned.type == Logic_Bans.Ban.BanType.IPBan)
                {   //Their IP has been banned, make something up!
                    plog.bSuccess     = false;
                    plog.loginMessage = "You have been temporarily suspended until " + banned.expiration.ToString("f", CultureInfo.CreateSpecificCulture("en-US"));

                    Log.write(TLog.Warning, "Failed login: "******" Alias: " + pkt.alias + " Reason: " + banned.type.ToString());
                    zone._client.send(plog);
                    return;
                }

                if (banned.type == Logic.Logic_Bans.Ban.BanType.ZoneBan)
                {   //They've been blocked from entering the zone, tell them how long they've got left on their ban
                    plog.bSuccess     = false;
                    plog.loginMessage = "You have been temporarily suspended from this zone until " + banned.expiration.ToString("f", CultureInfo.CreateSpecificCulture("en-US"));

                    Log.write(TLog.Warning, "Failed login: "******" Alias: " + pkt.alias + " Reason: " + banned.type.ToString());
                    zone._client.send(plog);
                    return;
                }

                if (banned.type == Logic.Logic_Bans.Ban.BanType.AccountBan)
                {   //They've been blocked from entering any zone, tell them when to come back
                    plog.bSuccess     = false;
                    plog.loginMessage = "Your account has been temporarily suspended until " + banned.expiration.ToString("f", CultureInfo.CreateSpecificCulture("en-US"));

                    Log.write(TLog.Warning, "Failed login: "******" Alias: " + pkt.alias + " Reason: " + banned.type.ToString());
                    zone._client.send(plog);
                    return;
                }

                //They made it!

                //We have the account associated!
                plog.permission = (PlayerPermission)account.permission;
                if (account.permission > (int)PlayerPermission.Sysop)
                {
                    plog.permission = PlayerPermission.Sysop;
                }

                //Attempt to find the related alias
                Data.DB.alias alias = db.alias.SingleOrDefault(a => a.name.Equals(pkt.alias));
                Data.DB.stats stats = null;

                //Is there already a player online under this alias?
                if (alias != null && zone._server._zones.Any(z => z.hasAliasPlayer(alias.id)))
                {
                    plog.bSuccess     = false;
                    plog.loginMessage = "Alias is currently in use.";

                    zone._client.send(plog);
                    return;
                }

                if (alias == null && !pkt.bCreateAlias)
                {       //Prompt him to create a new alias if he has room
                    if (account.alias.Count < 30)
                    {   //He has space! Prompt him to make a new alias
                        plog.bSuccess  = false;
                        plog.bNewAlias = true;

                        zone._client.send(plog);
                        return;
                    }
                    else
                    {
                        plog.bSuccess     = false;
                        plog.loginMessage = "Your account has reached the maximum number of aliases allowed.";

                        zone._client.send(plog);
                        return;
                    }
                }
                else if (alias == null && pkt.bCreateAlias)
                {       //We want to create a new alias!
                    alias = new InfServer.Data.DB.alias();

                    alias.name       = pkt.alias;
                    alias.creation   = DateTime.Now;
                    alias.account1   = account;
                    alias.IPAddress  = pkt.ipaddress;
                    alias.lastAccess = DateTime.Now;
                    alias.timeplayed = 0;

                    db.alias.InsertOnSubmit(alias);

                    Log.write(TLog.Normal, "Creating new alias '{0}' on account '{1}'", pkt.alias, account.name);
                }
                else if (alias != null)
                {       //We can't recreate an existing alias or login to one that isn't ours..
                    if (pkt.bCreateAlias ||
                        alias.account1 != account)
                    {
                        plog.bSuccess     = false;
                        plog.loginMessage = "The specified alias already exists.";

                        zone._client.send(plog);
                        return;
                    }
                }

                //Do we have a player row for this zone?
                player = db.players.SingleOrDefault(
                    plyr => plyr.alias1 == alias && plyr.zone1 == zone._zone);

                if (player == null)
                {       //We need to create another!
                    Log.write(TLog.Normal, "Player doesn't exist, creating another structure");
                    player = new InfServer.Data.DB.player();

                    player.squad1 = null;
                    player.zone   = zone._zone.id;
                    player.alias1 = alias;

                    player.lastAccess = DateTime.Now;
                    player.permission = 0;

                    //Create a blank stats row
                    stats = new InfServer.Data.DB.stats();

                    stats.zone    = zone._zone.id;
                    player.stats1 = stats;

                    db.stats.InsertOnSubmit(stats);
                    db.players.InsertOnSubmit(player);

                    //It's a first-time login, so no need to load stats
                    plog.bFirstTimeSetup = true;
                }
                else
                {       //Load the player details and stats!
                    plog.banner = player.banner;
                    if (account.id == 17 && alias.name.ToLower().Contains("hoto"))
                    {
                        plog.permission = 0;
                    }
                    else
                    {
                        plog.permission = (PlayerPermission)Math.Max(player.permission, (int)plog.permission);
                    }

                    if (player.permission > account.permission)
                    {
                        //He's a dev here, set the bool
                        plog.developer = true;
                    }

                    //Check for admin
                    if (Logic_Admins.checkAdmin(alias.name))
                    {
                        plog.admin = true;
                    }

                    plog.squad = (player.squad1 == null) ? "" : player.squad1.name;
                    if (player.squad1 != null)
                    {
                        plog.squadID = player.squad1.id;
                    }

                    stats = player.stats1;

                    plog.stats.zonestat1  = stats.zonestat1;
                    plog.stats.zonestat2  = stats.zonestat2;
                    plog.stats.zonestat3  = stats.zonestat3;
                    plog.stats.zonestat4  = stats.zonestat4;
                    plog.stats.zonestat5  = stats.zonestat5;
                    plog.stats.zonestat6  = stats.zonestat6;
                    plog.stats.zonestat7  = stats.zonestat7;
                    plog.stats.zonestat8  = stats.zonestat8;
                    plog.stats.zonestat9  = stats.zonestat9;
                    plog.stats.zonestat10 = stats.zonestat10;
                    plog.stats.zonestat11 = stats.zonestat11;
                    plog.stats.zonestat12 = stats.zonestat12;

                    plog.stats.kills         = stats.kills;
                    plog.stats.deaths        = stats.deaths;
                    plog.stats.killPoints    = stats.killPoints;
                    plog.stats.deathPoints   = stats.deathPoints;
                    plog.stats.assistPoints  = stats.assistPoints;
                    plog.stats.bonusPoints   = stats.bonusPoints;
                    plog.stats.vehicleKills  = stats.vehicleKills;
                    plog.stats.vehicleDeaths = stats.vehicleDeaths;
                    plog.stats.playSeconds   = stats.playSeconds;

                    plog.stats.cash            = stats.cash;
                    plog.stats.inventory       = new List <PlayerStats.InventoryStat>();
                    plog.stats.experience      = stats.experience;
                    plog.stats.experienceTotal = stats.experienceTotal;
                    plog.stats.skills          = new List <PlayerStats.SkillStat>();

                    //Convert the binary inventory/skill data
                    if (player.inventory != null)
                    {
                        DBHelpers.binToInventory(plog.stats.inventory, player.inventory);
                    }
                    if (player.skills != null)
                    {
                        DBHelpers.binToSkills(plog.stats.skills, player.skills);
                    }
                }

                //Rename him
                plog.alias = alias.name;

                //Try and submit any new rows before we try and use them
                try
                {
                    db.SubmitChanges();
                }
                catch (Exception e)
                {
                    plog.bSuccess     = false;
                    plog.loginMessage = "Unable to create new player / alias, please try again.";
                    Log.write(TLog.Exception, "Exception adding player or alias to DB: {0}", e);
                    zone._client.send(plog);
                    return;
                }

                //Add them
                if (zone.newPlayer(pkt.player.id, alias.name, player))
                {
                    plog.bSuccess = true;
                    Log.write("Player '{0}' logged into zone '{1}'", alias.name, zone._zone.name);

                    //Modify his alias IP address and access times
                    alias.IPAddress  = pkt.ipaddress.Trim();
                    alias.lastAccess = DateTime.Now;

                    //Change it
                    db.SubmitChanges();
                }
                else
                {
                    plog.bSuccess     = false;
                    plog.loginMessage = "Unknown login failure.";
                    Log.write("Failed adding player '{0}' from '{1}'", alias.name, zone._zone.name);
                }

                //Give them an answer
                zone._client.sendReliable(plog);
            }
        }
Example #3
0
        /// <summary>
        /// Handles a query packet
        /// </summary>
        static public void Handle_CS_ModQuery(CS_ModQuery <Zone> pkt, Zone zone)
        {
            using (InfantryDataContext db = zone._server.getContext())
            {
                switch (pkt.queryType)
                {
                case CS_ModQuery <Zone> .QueryType.aliastransfer:
                {
                    if (string.IsNullOrEmpty(pkt.query) || string.IsNullOrEmpty(pkt.aliasTo))
                    {
                        zone._server.sendMessage(zone, pkt.sender, "Wrong format typed.");
                        return;
                    }

                    //Who the alias is going to
                    Data.DB.alias paliasTo = db.alias.FirstOrDefault(aTo => string.Compare(aTo.name, pkt.aliasTo, true) == 0);
                    if (paliasTo == null)
                    {
                        zone._server.sendMessage(zone, pkt.sender, "Cant find the recipient's alias.");
                        return;
                    }

                    //The alias in question
                    Data.DB.alias  alias   = db.alias.FirstOrDefault(a => string.Compare(a.name, pkt.query, true) == 0);
                    Data.DB.player playerA = db.players.FirstOrDefault(p => string.Compare(p.alias1.name, pkt.query, true) == 0);
                    if (alias == null)
                    {
                        zone._server.sendMessage(zone, pkt.sender, "Can't find the alias in question, maybe its not created yet.");
                        return;
                    }

                    if (playerA == null)
                    {
                        //Since structure doesn't exist, go ahead and transfer
                        alias.IPAddress  = paliasTo.IPAddress.Trim();
                        alias.timeplayed = 0;
                        alias.account    = paliasTo.account;
                        alias.account1   = paliasTo.account1;
                        db.SubmitChanges();
                        zone._server.sendMessage(zone, pkt.sender, "Alias transfer completed.");
                        return;
                    }

                    //Check for a squad
                    if (playerA.squad != null)
                    {
                        IQueryable <Data.DB.player> squadmates = db.players.Where(plyr => plyr.zone == playerA.zone && plyr.squad != null && plyr.squad == playerA.squad);
                        if (playerA.squad1.owner == playerA.id)
                        {
                            if (squadmates.Count() > 1)
                            {
                                Data.DB.player temp = squadmates.FirstOrDefault(p => p.id != playerA.id);
                                //Since the player is the owner, lets just give it to someone else
                                temp.squad1.owner = temp.id;
                            }
                            else if (squadmates.Count() == 1)
                            {
                                //Lets delete the squad
                                db.squads.DeleteOnSubmit(playerA.squad1);
                                db.SubmitChanges();
                            }
                        }
                        playerA.squad1 = null;
                        playerA.squad  = null;
                    }
                    //Lets delete stats/player structures
                    //Note: the server will treat this as a new alias and create structures
                    db.stats.DeleteOnSubmit(playerA.stats1);
                    db.players.DeleteOnSubmit(playerA);

                    //Now lets transfer
                    alias.IPAddress  = paliasTo.IPAddress.Trim();
                    alias.timeplayed = 0;
                    alias.account    = paliasTo.account;
                    alias.account1   = paliasTo.account1;
                    db.SubmitChanges();
                    zone._server.sendMessage(zone, pkt.sender, "Alias transfer completed.");
                }
                break;

                case CS_ModQuery <Zone> .QueryType.aliasremove:
                {
                    if (string.IsNullOrEmpty(pkt.query))
                    {
                        zone._server.sendMessage(zone, pkt.sender, "Wrong format typed.");
                        return;
                    }

                    //Lets get all account related info then delete it
                    Data.DB.alias  palias = db.alias.FirstOrDefault(a => string.Compare(a.name, pkt.query, true) == 0);
                    Data.DB.player player = db.players.FirstOrDefault(p => string.Compare(p.alias1.name, pkt.query, true) == 0);
                    if (palias == null)
                    {
                        zone._server.sendMessage(zone, pkt.sender, "Cannot find the specified alias.");
                        return;
                    }

                    if (player == null)
                    {
                        zone._server.sendMessage(zone, pkt.sender, "Cannot find the specified player.");
                        return;
                    }

                    //Check for a squad
                    if (player.squad != null)
                    {
                        IQueryable <Data.DB.player> squadmates = db.players.Where(plyr => plyr.zone == player.zone && plyr.squad != null && plyr.squad == player.squad);
                        if (player.squad1.owner == player.id)
                        {
                            if (squadmates.Count() > 1)
                            {
                                Data.DB.player temp = squadmates.FirstOrDefault(p => p.id != player.id);
                                //Since the player is the owner, lets just give it to someone else
                                temp.squad1.owner = temp.id;
                            }
                            else if (squadmates.Count() == 1)
                            {
                                //Lets delete the squad
                                db.squads.DeleteOnSubmit(player.squad1);
                            }
                            db.SubmitChanges();
                        }
                        player.squad1 = null;
                        player.squad  = null;
                    }

                    //Now lets remove stats
                    db.stats.DeleteOnSubmit(player.stats1);
                    //Next the player structure
                    db.players.DeleteOnSubmit(player);
                    //Finally the alias
                    db.alias.DeleteOnSubmit(palias);
                    db.SubmitChanges();
                    zone._server.sendMessage(zone, pkt.sender, "Alias has been deleted.");
                }
                break;

                case CS_ModQuery <Zone> .QueryType.aliasrename:
                {
                    if (string.IsNullOrEmpty(pkt.query))
                    {
                        zone._server.sendMessage(zone, pkt.sender, "Wrong format typed.");
                        return;
                    }

                    //Get all account related info
                    Data.DB.alias paliasTo = db.alias.FirstOrDefault(aTo => string.Compare(aTo.name, pkt.aliasTo, true) == 0);
                    Data.DB.alias alias    = db.alias.FirstOrDefault(a => string.Compare(a.name, pkt.query, true) == 0);
                    //Player even alive?
                    if (paliasTo == null)
                    {
                        zone._server.sendMessage(zone, pkt.sender, "Cannot find the specified alias.");
                        return;
                    }

                    string name = paliasTo.name;

                    //Does the payload already exist?
                    if (alias == null)
                    {
                        paliasTo.name = pkt.query;
                        db.SubmitChanges();
                        zone._server.sendMessage(zone, pkt.sender, "Renamed player " + name + " to " + pkt.query + " has been completed.");
                        return;
                    }

                    if (alias.account1 != paliasTo.account1)
                    {
                        zone._server.sendMessage(zone, pkt.sender, "That alias is already being used.");
                        return;
                    }

                    if (alias.id != paliasTo.id)
                    {
                        zone._server.sendMessage(zone, pkt.sender, "Cannot change an alias to one already existing on the account.");
                        return;
                    }

                    paliasTo.name = pkt.query;
                    db.SubmitChanges();

                    zone._server.sendMessage(zone, pkt.sender, "Renamed player " + name + " to " + pkt.query + " has been completed.");
                }
                break;

                case CS_ModQuery <Zone> .QueryType.mod:
                {
                    if (string.IsNullOrEmpty(pkt.query))
                    {
                        zone._server.sendMessage(zone, pkt.sender, "Wrong format typed.");
                        return;
                    }

                    //Lets get all account related info
                    Data.DB.alias   palias  = db.alias.FirstOrDefault(a => string.Compare(a.name, pkt.query, true) == 0);
                    Data.DB.account account = db.accounts.FirstOrDefault(p => p.id == palias.account1.id);
                    if (palias == null)
                    {
                        zone._server.sendMessage(zone, pkt.sender, "Cannot find the specified alias.");
                        return;
                    }

                    if (account == null)
                    {
                        zone._server.sendMessage(zone, pkt.sender, "Cannot find the specified account.");
                        return;
                    }

                    //Lets mod/de-mod them
                    account.permission = pkt.level;
                    db.SubmitChanges();
                    zone._server.sendMessage(zone, pkt.sender, "Changing player " + palias.name + "'s level to " + pkt.level + " has been completed.");
                }
                break;

                case CS_ModQuery <Zone> .QueryType.dev:
                {
                    if (string.IsNullOrEmpty(pkt.query))
                    {
                        zone._server.sendMessage(zone, pkt.sender, "Wrong format typed.");
                        return;
                    }

                    //Lets get all account related info
                    Data.DB.player player = (from plyr in db.players
                                             where string.Compare(plyr.alias1.name, pkt.query, true) == 0 && plyr.zone1 == zone._zone
                                             select plyr).FirstOrDefault();
                    if (player == null)
                    {
                        zone._server.sendMessage(zone, pkt.sender, "Cannot find the specified alias.");
                        return;
                    }

                    //Lets mod/de-mod them
                    player.permission = (short)pkt.level;

                    db.SubmitChanges();
                    zone._server.sendMessage(zone, pkt.sender, "Changing player " + player.alias1.name + "'s dev level to " + pkt.level + " has been completed.");
                }
                break;

                case CS_ModQuery <Zone> .QueryType.squadtransfer:
                {
                    if (string.IsNullOrEmpty(pkt.aliasTo) || string.IsNullOrEmpty(pkt.query))
                    {
                        zone._server.sendMessage(zone, pkt.sender, "Wrong format typed.");
                        return;
                    }

                    //Lets find the player first
                    Data.DB.player dbplayer = db.zones.First(z => z.id == zone._zone.id).players.FirstOrDefault(p => string.Compare(p.alias1.name, pkt.aliasTo, true) == 0);
                    if (dbplayer == null)
                    {
                        zone._server.sendMessage(zone, pkt.sender, "Cannot find the player.");
                        return;
                    }

                    //Lets find the squad in question
                    Data.DB.squad squad = db.squads.First(s => string.Compare(s.name, pkt.query, true) == 0 && s.zone == zone._zone.id);
                    if (squad == null)
                    {
                        zone._server.sendMessage(zone, pkt.sender, "Cannot find the specified squad.");
                        return;
                    }

                    //Are they in a squad?
                    if (dbplayer.squad != null)
                    {
                        //Is it the same squad?
                        if (dbplayer.squad != squad.id)
                        {
                            zone._server.sendMessage(zone, pkt.sender, "That player isn't on the same squad.");
                            return;
                        }
                        //Transfer
                        dbplayer.squad1.owner = dbplayer.id;
                    }
                    else
                    {
                        dbplayer.squad        = squad.id;
                        dbplayer.squad1.owner = dbplayer.id;
                    }
                    db.SubmitChanges();
                    zone._server.sendMessage(zone, dbplayer.alias1.name, "You have been promoted to squad captain of " + dbplayer.squad1.name);
                    zone._server.sendMessage(zone, dbplayer.alias1.name, "Please relog to complete the process.");
                    zone._server.sendMessage(zone, pkt.sender, "Squad transferring is complete.");
                }
                break;

                case CS_ModQuery <Zone> .QueryType.squadjoin:
                {
                    if (string.IsNullOrWhiteSpace(pkt.aliasTo) || string.IsNullOrWhiteSpace(pkt.query))
                    {
                        zone._server.sendMessage(zone, pkt.sender, "Wrong format typed.");
                        return;
                    }

                    //Lets find the player first
                    Data.DB.player dbplayer = db.zones.First(z => z.id == zone._zone.id).players.FirstOrDefault(p => string.Compare(p.alias1.name, pkt.aliasTo, true) == 0);
                    if (dbplayer == null)
                    {
                        zone._server.sendMessage(zone, pkt.sender, "Cannot find the player.");
                        return;
                    }

                    //Lets find the squad in question
                    Data.DB.squad squad = db.squads.FirstOrDefault(s => string.Compare(s.name, pkt.query, true) == 0 && s.zone == zone._zone.id);
                    if (squad == null)
                    {
                        zone._server.sendMessage(zone, pkt.sender, "Cannot find the specified squad.");
                        return;
                    }

                    //Already squad joined somewhere?
                    if (dbplayer.squad != null)
                    {
                        //Get his squad brothers! (if any...)
                        IQueryable <Data.DB.player> squadmates = db.players.Where(p => p.zone == dbplayer.zone && p.squad != null && p.squad == dbplayer.squad);

                        //Is he the captain?
                        if (dbplayer.squad1.owner == dbplayer.id)
                        {           //We might need to dissolve the team!
                            if (squadmates.Count() == 1)
                            {       //He's the only one left on the squad... dissolve it!
                                db.squads.DeleteOnSubmit(dbplayer.squad1);
                                db.SubmitChanges();
                                dbplayer.squad1 = null;
                                dbplayer.squad  = null;
                            }
                            else
                            {           //There are other people on the squad, transfer it to someone
                                Data.DB.player transferPlayer = squadmates.FirstOrDefault(p => p.id != dbplayer.id);
                                dbplayer.squad1.owner = transferPlayer.id;
                                db.SubmitChanges();
                                zone._server.sendMessage(zone, transferPlayer.alias1.name, "You have been promoted to squad captain of " + transferPlayer.squad1.name);
                            }
                        }
                    }

                    dbplayer.squad = squad.id;
                    db.SubmitChanges();
                    zone._server.sendMessage(zone, dbplayer.alias1.name, "You have joined " + squad.name);
                    zone._server.sendMessage(zone, dbplayer.alias1.name, "Please relog to complete the process.");
                    zone._server.sendMessage(zone, pkt.sender, "Squad joining completed.");
                }
                break;

                case CS_ModQuery <Zone> .QueryType.powered:
                {
                    if (string.IsNullOrWhiteSpace(pkt.query))
                    {
                        zone._server.sendMessage(zone, pkt.sender, "Payload cannot be empty.");
                        return;
                    }

                    if (pkt.query.Equals("list"))
                    {
                        Data.DB.player sender = db.players.FirstOrDefault(p => string.Compare(p.alias1.name, pkt.sender, true) == 0 && p.zone == zone._zone.id);
                        if (sender == null)
                        {
                            return;
                        }

                        SortedDictionary <string, string> powered = new SortedDictionary <string, string>();
                        string pAlias;
                        foreach (Zone z in zone._server._zones)
                        {
                            foreach (KeyValuePair <int, Zone.Player> Player in z._players)
                            {
                                pAlias = Player.Value.alias;
                                var alias = db.alias.SingleOrDefault(p => string.Compare(p.name, pAlias, true) == 0);
                                if (alias == null)
                                {
                                    continue;
                                }
                                if (alias.name == pkt.sender)
                                {
                                    continue;
                                }
                                //Are they a global mod?
                                if (alias.account1.permission > 0)
                                {
                                    //Are they higher than us?
                                    if (alias.account1.permission > sender.alias1.account1.permission &&
                                        alias.account1.permission > sender.permission)
                                    {
                                        continue;
                                    }
                                    powered.Add(pAlias, string.Format("*{0} - Lvl({1})", pAlias, alias.account1.permission.ToString()));
                                }
                                else
                                {
                                    var player = db.zones.First(zones => zones.id == z._zone.id).players.First(p => p.alias1 == alias);
                                    if (player != null && player.permission > 0)
                                    {
                                        //Are they higher than us?
                                        if (player.permission > sender.permission &&
                                            player.alias1.account1.permission > sender.alias1.account1.permission)
                                        {
                                            continue;
                                        }
                                        powered.Add(pAlias, string.Format("*{0} - Lvl({1})(dev)", pAlias, player.permission.ToString()));
                                    }
                                }
                            }
                        }

                        //Now send it!
                        if (powered.Count > 0)
                        {
                            foreach (string str in powered.Values)
                            {
                                zone._server.sendMessage(zone, pkt.sender, str);
                            }
                        }
                        else
                        {
                            zone._server.sendMessage(zone, pkt.sender, "Empty.");
                        }
                    }
                }
                break;

                case CS_ModQuery <Zone> .QueryType.find:
                {
                    zone._server.sendMessage(zone, pkt.sender, "&Search Results:");

                    Data.DB.alias alias = db.alias.SingleOrDefault(ali => string.Compare(ali.name, pkt.query, true) == 0);
                    if (alias == null)
                    {
                        zone._server.sendMessage(zone, pkt.sender, "Cannot find the specified alias.");
                        return;
                    }

                    bool found = false;
                    IQueryable <Data.DB.alias> foundAlias = db.alias.Where(d => (d.IPAddress.Equals(alias.IPAddress) || d.account == alias.account));
                    foreach (KeyValuePair <string, Zone.Player> player in zone._server._players)
                    {
                        foreach (Data.DB.alias p in foundAlias)
                        {
                            if (player.Value.alias.Equals(p.name))
                            {
                                zone._server.sendMessage(zone, pkt.sender, string.Format("*Found: {0} Zone: {1} Arena: {2}", p.name, player.Value.zone._zone.name, !String.IsNullOrWhiteSpace(player.Value.arena) ? player.Value.arena : "Unknown Arena"));
                                found = true;
                            }
                        }
                    }
                    if (!found)
                    {
                        zone._server.sendMessage(zone, pkt.sender, "Cannot find the specified alias.");
                    }
                }
                break;
                }
            }
        }
Example #4
0
        /// <summary>
        /// Handles a query packet
        /// </summary>
        static public void Handle_CS_Ban(CS_Ban <Zone> pkt, Zone zone)
        {
            using (InfantryDataContext db = zone._server.getContext())
            {
                Data.DB.alias dbplayer = db.alias.First(p => string.Compare(p.name, pkt.alias, true) == 0);

                //Lets check to see if they are banned already
                foreach (Data.DB.ban b in db.bans.Where(b => b.account == dbplayer.account1.id))
                {
                    //Same type?
                    if (b.type != (short)pkt.banType)
                    {
                        continue;
                    }

                    //Zone ban?
                    if ((short)pkt.banType == (int)Logic_Bans.Ban.BanType.ZoneBan)
                    {
                        if (b.zone == null)
                        {
                            continue;
                        }
                        if (b.zone != zone._zone.id)
                        {
                            continue;
                        }
                    }

                    if (pkt.time != 0)
                    {
                        //Dont update old bans
                        if (DateTime.Now > b.expires)
                        {
                            continue;
                        }
                        b.expires = b.expires.AddMinutes(pkt.time);
                    }
                    //Are we unbanning them?
                    else if (pkt.time == 0)
                    {
                        b.expires = DateTime.Now;
                    }

                    b.reason = b.reason.ToString();

                    db.SubmitChanges();
                    return;
                }

                Data.DB.ban newBan = new Data.DB.ban();
                switch (pkt.banType)
                {
                case CS_Ban <Zone> .BanType.zone:
                {
                    //Check for updating the ban
                    newBan.type = (short)Logic_Bans.Ban.BanType.ZoneBan;
                    if (pkt.time == 0)
                    {
                        newBan.expires = DateTime.Now;
                    }
                    else
                    {
                        newBan.expires = DateTime.Now.AddMinutes(pkt.time);
                    }
                    newBan.created   = DateTime.Now;
                    newBan.uid1      = pkt.UID1;
                    newBan.uid2      = pkt.UID2;
                    newBan.uid3      = pkt.UID3;
                    newBan.account   = dbplayer.account;
                    newBan.IPAddress = dbplayer.IPAddress;
                    newBan.zone      = zone._zone.id;
                    newBan.reason    = pkt.reason;
                    newBan.name      = dbplayer.name;
                }
                break;

                case CS_Ban <Zone> .BanType.account:
                {
                    newBan.type = (short)Logic_Bans.Ban.BanType.AccountBan;
                    if (pkt.time == 0)
                    {
                        newBan.expires = DateTime.Now;
                    }
                    else
                    {
                        newBan.expires = DateTime.Now.AddMinutes(pkt.time);
                    }
                    newBan.created   = DateTime.Now;
                    newBan.uid1      = pkt.UID1;
                    newBan.uid2      = pkt.UID2;
                    newBan.uid3      = pkt.UID3;
                    newBan.account   = dbplayer.account;
                    newBan.IPAddress = dbplayer.IPAddress;
                    newBan.reason    = pkt.reason;
                    newBan.name      = dbplayer.name;
                }
                break;

                case CS_Ban <Zone> .BanType.ip:
                {
                    newBan.type = (short)Logic_Bans.Ban.BanType.IPBan;
                    if (pkt.time == 0)
                    {
                        newBan.expires = DateTime.Now;
                    }
                    else
                    {
                        newBan.expires = DateTime.Now.AddMinutes(pkt.time);
                    }
                    newBan.created   = DateTime.Now;
                    newBan.uid1      = pkt.UID1;
                    newBan.uid2      = pkt.UID2;
                    newBan.uid3      = pkt.UID3;
                    newBan.account   = dbplayer.account;
                    newBan.IPAddress = dbplayer.IPAddress;
                    newBan.reason    = pkt.reason;
                    newBan.name      = dbplayer.name;
                }
                break;

                case CS_Ban <Zone> .BanType.global:
                {
                    newBan.type = (short)Logic_Bans.Ban.BanType.GlobalBan;
                    if (pkt.time == 0)
                    {
                        newBan.expires = DateTime.Now;
                    }
                    else
                    {
                        newBan.expires = DateTime.Now.AddMinutes(pkt.time);
                    }
                    newBan.created   = DateTime.Now;
                    newBan.uid1      = pkt.UID1;
                    newBan.uid2      = pkt.UID2;
                    newBan.uid3      = pkt.UID3;
                    newBan.account   = dbplayer.account;
                    newBan.IPAddress = dbplayer.IPAddress;
                    newBan.reason    = pkt.reason;
                    newBan.name      = dbplayer.name;
                }
                break;
                }
                db.bans.InsertOnSubmit(newBan);
                db.SubmitChanges();
            }
        }
        /// <summary>
        /// Handles a player stat request
        /// </summary>
        static public void Handle_CS_PlayerStatsRequest(CS_PlayerStatsRequest <Zone> pkt, Zone zone)
        {       //Attempt to find the player in question
            Zone.Player player = zone.getPlayer(pkt.player.id);
            if (player == null)
            {   //Make a note
                Log.write(TLog.Warning, "Ignoring player stats request for #{0}, not present in zone mirror.", pkt.player.id);
                return;
            }

            using (InfantryDataContext db = zone._server.getContext())
            {   //What sort of request are we dealing with?
                switch (pkt.type)
                {
                case CS_PlayerStatsRequest <Zone> .ChartType.ScoreLifetime:
                {               //Get the top100 stats sorted by points
                    var stats = (from st in db.stats
                                 where st.zone1 == zone._zone
                                 orderby st.assistPoints + st.bonusPoints + st.killPoints descending
                                 select st).Take(100);

                    MemoryStream stream = new MemoryStream();
                    foreach (Data.DB.stats lifetime in stats)
                    {
                        if (lifetime != null && writeElementToBuffer(lifetime, stream) == false)
                        {
                            continue;
                        }
                    }

                    SC_PlayerStatsResponse <Zone> response = new SC_PlayerStatsResponse <Zone>();

                    response.player  = pkt.player;
                    response.type    = CS_PlayerStatsRequest <Zone> .ChartType.ScoreLifetime;
                    response.columns = "Top100 Lifetime Score,Name,Squad";
                    response.data    = stream.ToArray();

                    zone._client.sendReliable(response, 1);
                }
                break;

                case CS_PlayerStatsRequest <Zone> .ChartType.ScoreDaily:
                {
                    DateTime now = DateTime.Today;

                    //Get the top100 stats sorted by points
                    //For today's date
                    var daily = (from dt in db.statsDailies
                                 where dt.zone1 == zone._zone && dt.date >= now
                                 orderby dt.assistPoints + dt.bonusPoints + dt.killPoints descending
                                 select dt).Take(100);

                    //Are they requesting a specific date?
                    if (pkt.options != "")
                    {
                        //Player wants to see yesterday's date
                        if (pkt.options.Equals("-1"))
                        {
                            DateTime today = now;
                            now   = now.AddDays(-1);
                            daily = (from dt in db.statsDailies
                                     where dt.zone1 == zone._zone && dt.date >= now && dt.date < today
                                     orderby dt.assistPoints + dt.bonusPoints + dt.killPoints descending
                                     select dt).Take(100);
                        }
                        else         //Specific date
                        {
                            string[] args  = pkt.options.Split('-');
                            string   final = string.Join("/", args);
                            try
                            {
                                now = DateTime.Parse(final, System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat);
                            }
                            catch (FormatException)
                            {
                                //Wrong format, use yesterday as default
                                now = (now.AddDays(-1));
                            }
                            DateTime add = now.AddDays(1);

                            daily = (from dt in db.statsDailies
                                     where dt.zone1 == zone._zone && dt.date >= now && dt.date < add
                                     orderby dt.assistPoints + dt.bonusPoints + dt.killPoints descending
                                     select dt).Take(100);
                        }
                    }

                    MemoryStream stream = new MemoryStream();
                    try
                    {
                        foreach (Data.DB.statsDaily day in daily)
                        {
                            BinaryWriter bw = new BinaryWriter(stream);
                            bw.Write(day.players[0].alias1.name.ToCharArray());
                            bw.Write((byte)0);

                            Data.DB.squad squad     = day.players[0].squad1;
                            string        squadname = "";
                            if (squad != null)
                            {
                                squadname = squad.name;
                            }

                            bw.Write(squadname.ToCharArray());
                            bw.Write((byte)0);

                            bw.Write((short)2);
                            bw.Write(day.vehicleDeaths);
                            bw.Write(day.vehicleKills);
                            bw.Write(day.killPoints);
                            bw.Write(day.deathPoints);
                            bw.Write(day.assistPoints);
                            bw.Write(day.bonusPoints);
                            bw.Write(day.kills);
                            bw.Write(day.deaths);
                            bw.Write((int)0);
                            bw.Write(day.playSeconds);
                        }
                    }
                    catch (Exception e)
                    {
                        Log.write(TLog.Warning, "WriteElementDaily " + e);
                    }

                    SC_PlayerStatsResponse <Zone> response = new SC_PlayerStatsResponse <Zone>();

                    response.player  = pkt.player;
                    response.type    = CS_PlayerStatsRequest <Zone> .ChartType.ScoreDaily;
                    response.columns = "Top100 Daily Score,Name,Squad";
                    response.data    = stream.ToArray();

                    zone._client.sendReliable(response, 1);
                }
                break;

                case CS_PlayerStatsRequest <Zone> .ChartType.ScoreWeekly:
                {
                    DateTime now = DateTime.Today;
                    if (((int)now.DayOfWeek) > 0)
                    {
                        now = now.AddDays(-((int)now.DayOfWeek));
                    }

                    //Get the top100 stats sorted by points
                    //For this week
                    var weekly = (from wt in db.statsWeeklies
                                  where wt.zone1 == zone._zone && wt.date >= now
                                  orderby wt.assistPoints + wt.bonusPoints + wt.killPoints descending
                                  select wt).Take(100);

                    //Are they requesting a specific date?
                    if (pkt.options != "")
                    {
                        //Player wants to see last week's date
                        if (pkt.options.Equals("-1"))
                        {
                            DateTime today = now;
                            now    = now.AddDays(-7);
                            weekly = (from wt in db.statsWeeklies
                                      where wt.zone1 == zone._zone && wt.date >= now && wt.date < today
                                      orderby wt.assistPoints + wt.bonusPoints + wt.killPoints descending
                                      select wt).Take(100);
                        }
                        else         //Specific date
                        {
                            string[] args  = pkt.options.Split('-');
                            string   final = string.Join("/", args);
                            try
                            {
                                now = DateTime.Parse(final, System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat);
                            }
                            catch (FormatException)
                            {
                                //Wrong format, use last week as default
                                now = (now.AddDays(-7));
                            }
                            DateTime add = now.AddDays(7);

                            weekly = (from wt in db.statsWeeklies
                                      where wt.zone1 == zone._zone && wt.date >= now && wt.date < add
                                      orderby wt.assistPoints + wt.bonusPoints + wt.killPoints descending
                                      select wt).Take(100);
                        }
                    }

                    MemoryStream stream = new MemoryStream();
                    try
                    {
                        foreach (Data.DB.statsWeekly week in weekly)
                        {
                            BinaryWriter bw = new BinaryWriter(stream);
                            bw.Write(week.players[0].alias1.name.ToCharArray());
                            bw.Write((byte)0);

                            Data.DB.squad squad     = week.players[0].squad1;
                            string        squadname = "";
                            if (squad != null)
                            {
                                squadname = squad.name;
                            }

                            bw.Write(squadname.ToCharArray());
                            bw.Write((byte)0);

                            bw.Write((short)2);
                            bw.Write(week.vehicleDeaths);
                            bw.Write(week.vehicleKills);
                            bw.Write(week.killPoints);
                            bw.Write(week.deathPoints);
                            bw.Write(week.assistPoints);
                            bw.Write(week.bonusPoints);
                            bw.Write(week.kills);
                            bw.Write(week.deaths);
                            bw.Write((int)0);
                            bw.Write(week.playSeconds);
                        }
                    }
                    catch (Exception e)
                    {
                        Log.write(TLog.Warning, "WriteElementWeekly " + e);
                    }

                    SC_PlayerStatsResponse <Zone> response = new SC_PlayerStatsResponse <Zone>();

                    response.player  = pkt.player;
                    response.type    = CS_PlayerStatsRequest <Zone> .ChartType.ScoreWeekly;
                    response.columns = "Top100 Weekly Score,Name,Squad";
                    response.data    = stream.ToArray();

                    zone._client.sendReliable(response, 1);
                }
                break;

                case CS_PlayerStatsRequest <Zone> .ChartType.ScoreMonthly:
                {
                    DateTime now = DateTime.Today;
                    if (((int)now.Day - 1) > 1)
                    {
                        now = now.AddDays(-(((int)now.Day) - 1));
                    }

                    //Get the top100 stats sorted by points
                    //For this month
                    var monthly = (from mt in db.statsMonthlies
                                   where mt.zone1 == zone._zone && mt.date >= now
                                   orderby mt.assistPoints + mt.bonusPoints + mt.killPoints descending
                                   select mt).Take(100);

                    //Are they requesting a specific date?
                    if (pkt.options != "")
                    {
                        //Player wants to see last month's date
                        if (pkt.options.Equals("-1"))
                        {
                            DateTime today = now;
                            now     = now.AddMonths(-1);
                            monthly = (from mt in db.statsMonthlies
                                       where mt.zone1 == zone._zone && mt.date >= now && mt.date < today
                                       orderby mt.assistPoints + mt.bonusPoints + mt.killPoints descending
                                       select mt).Take(100);
                        }
                        else         //Specific date
                        {
                            string[] args  = pkt.options.Split('-');
                            string   final = string.Join("/", args);
                            //Since the client only gives month/year, lets start from day 1
                            final = String.Format("{0}/01", final);
                            try
                            {
                                now = DateTime.Parse(final, System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat);
                            }
                            catch (FormatException)
                            {
                                //Wrong format, use last month as default
                                now = (now.AddMonths(-1));
                            }
                            DateTime add = now.AddMonths(1);

                            monthly = (from mt in db.statsMonthlies
                                       where mt.zone1 == zone._zone && mt.date >= now && mt.date < add
                                       orderby mt.assistPoints + mt.bonusPoints + mt.killPoints descending
                                       select mt).Take(100);
                        }
                    }

                    MemoryStream stream = new MemoryStream();
                    try
                    {
                        foreach (Data.DB.statsMonthly month in monthly)
                        {
                            BinaryWriter bw = new BinaryWriter(stream);
                            bw.Write(month.players[0].alias1.name.ToCharArray());
                            bw.Write((byte)0);

                            Data.DB.squad squad     = month.players[0].squad1;
                            string        squadname = "";
                            if (squad != null)
                            {
                                squadname = squad.name;
                            }

                            bw.Write(squadname.ToCharArray());
                            bw.Write((byte)0);

                            bw.Write((short)2);
                            bw.Write(month.vehicleDeaths);
                            bw.Write(month.vehicleKills);
                            bw.Write(month.killPoints);
                            bw.Write(month.deathPoints);
                            bw.Write(month.assistPoints);
                            bw.Write(month.bonusPoints);
                            bw.Write(month.kills);
                            bw.Write(month.deaths);
                            bw.Write((int)0);
                            bw.Write(month.playSeconds);
                        }
                    }
                    catch (Exception e)
                    {
                        Log.write(TLog.Warning, "WriteElementMonthly " + e);
                    }

                    SC_PlayerStatsResponse <Zone> response = new SC_PlayerStatsResponse <Zone>();

                    response.player  = pkt.player;
                    response.type    = CS_PlayerStatsRequest <Zone> .ChartType.ScoreMonthly;
                    response.columns = "Top100 Monthly Score,Name,Squad";
                    response.data    = stream.ToArray();

                    zone._client.sendReliable(response, 1);
                }
                break;

                case CS_PlayerStatsRequest <Zone> .ChartType.ScoreYearly:
                {
                    DateTime now = DateTime.Today;
                    if (((int)now.Month) > 1)
                    {
                        now = now.AddMonths(-((int)DateTime.Now.Month));
                    }

                    //Get the top100 stats sorted by points
                    var yearly = (from yt in db.statsYearlies
                                  where yt.zone1 == zone._zone && yt.date >= now
                                  orderby yt.assistPoints + yt.bonusPoints + yt.killPoints descending
                                  select yt).Take(100);

                    //Are they requesting a specific date?
                    if (pkt.options != "")
                    {
                        //Player wants to see last years date
                        if (pkt.options.Equals("-1"))
                        {
                            now    = now.AddYears(-1);
                            yearly = (from yt in db.statsYearlies
                                      where yt.zone1 == zone._zone && yt.date >= now
                                      orderby yt.assistPoints + yt.bonusPoints + yt.killPoints descending
                                      select yt).Take(100);
                        }
                        else         //Specific date
                        {
                            //Since the client only gives the year, lets start from jan 1st
                            string final = String.Format("{0}/01/01", pkt.options);
                            try
                            {
                                now = DateTime.Parse(final, System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat);
                            }
                            catch (FormatException)
                            {
                                //Wrong format, use last year as default
                                now = (now.AddYears(-1));
                            }
                            DateTime add = now.AddYears(1);

                            yearly = (from yt in db.statsYearlies
                                      where yt.zone1 == zone._zone && yt.date >= now && yt.date <= add
                                      orderby yt.assistPoints + yt.bonusPoints + yt.killPoints descending
                                      select yt).Take(100);
                        }
                    }

                    MemoryStream stream = new MemoryStream();
                    try
                    {
                        foreach (Data.DB.statsYearly year in yearly)
                        {
                            BinaryWriter bw = new BinaryWriter(stream);
                            bw.Write(year.players[0].alias1.name.ToCharArray());
                            bw.Write((byte)0);

                            Data.DB.squad squad     = year.players[0].squad1;
                            string        squadname = "";
                            if (squad != null)
                            {
                                squadname = squad.name;
                            }

                            bw.Write(squadname.ToCharArray());
                            bw.Write((byte)0);

                            bw.Write((short)2);
                            bw.Write(year.vehicleDeaths);
                            bw.Write(year.vehicleKills);
                            bw.Write(year.killPoints);
                            bw.Write(year.deathPoints);
                            bw.Write(year.assistPoints);
                            bw.Write(year.bonusPoints);
                            bw.Write(year.kills);
                            bw.Write(year.deaths);
                            bw.Write((int)0);
                            bw.Write(year.playSeconds);
                        }
                    }
                    catch (Exception e)
                    {
                        Log.write(TLog.Warning, "WriteElementYear " + e);
                    }

                    SC_PlayerStatsResponse <Zone> response = new SC_PlayerStatsResponse <Zone>();

                    response.player  = pkt.player;
                    response.type    = CS_PlayerStatsRequest <Zone> .ChartType.ScoreYearly;
                    response.columns = "Top100 Yearly Score,Name,Squad";
                    response.data    = stream.ToArray();

                    zone._client.sendReliable(response, 1);
                }
                break;

                case CS_PlayerStatsRequest <Zone> .ChartType.ScoreHistoryDaily:
                {
                    Data.DB.alias  getAlias  = db.alias.FirstOrDefault(a => a.name.Equals(pkt.options));
                    Data.DB.player getPlayer = db.players.FirstOrDefault(p => p.alias1 == getAlias && p.zone == zone._zone.id);
                    if (getPlayer == null)
                    {
                        return;
                    }

                    //Lets give them a year's worth
                    DateTime now = DateTime.Today;
                    if (((int)now.DayOfYear - 1) > 1)
                    {
                        now = now.AddDays(-(((int)now.DayOfYear) - 1));
                    }

                    DateTime today = DateTime.Today;
                    var      daily = (from dt in db.statsDailies
                                      where dt.zone1 == zone._zone && dt.date >= now && dt.date < today
                                      orderby dt.date descending
                                      select dt);

                    MemoryStream stream = new MemoryStream();
                    try
                    {
                        foreach (Data.DB.statsDaily day in daily)
                        {
                            BinaryWriter bw = new BinaryWriter(stream);
                            bw.Write(day.players[0].alias1.name.ToCharArray());
                            bw.Write((byte)0);

                            Data.DB.squad squad     = day.players[0].squad1;
                            string        squadname = "";
                            if (squad != null)
                            {
                                squadname = squad.name;
                            }

                            bw.Write(squadname.ToCharArray());
                            bw.Write((byte)0);

                            bw.Write((short)2);
                            bw.Write(day.vehicleDeaths);
                            bw.Write(day.vehicleKills);
                            bw.Write(day.killPoints);
                            bw.Write(day.deathPoints);
                            bw.Write(day.assistPoints);
                            bw.Write(day.bonusPoints);
                            bw.Write(day.kills);
                            bw.Write(day.deaths);
                            bw.Write((int)0);
                            bw.Write(day.playSeconds);
                        }
                    }
                    catch (Exception e)
                    {
                        Log.write(TLog.Warning, "WriteElementHistoryDailly " + e);
                    }

                    SC_PlayerStatsResponse <Zone> response = new SC_PlayerStatsResponse <Zone>();

                    response.player  = pkt.player;
                    response.type    = CS_PlayerStatsRequest <Zone> .ChartType.ScoreHistoryDaily;
                    response.columns = "ScoreHistory Daily Score,Name,Squad";
                    response.data    = stream.ToArray();

                    zone._client.sendReliable(response, 1);
                }
                break;

                case CS_PlayerStatsRequest <Zone> .ChartType.ScoreHistoryWeekly:
                {
                    Data.DB.alias  getAlias  = db.alias.FirstOrDefault(a => a.name.Equals(pkt.options));
                    Data.DB.player getPlayer = db.players.FirstOrDefault(p => p.alias1 == getAlias && p.zone == zone._zone.id);
                    if (getPlayer == null)
                    {
                        return;
                    }

                    //Lets give them a year's worth
                    DateTime now = DateTime.Today;
                    if (((int)now.DayOfWeek) > 0)
                    {
                        now = now.AddDays(-(((int)now.DayOfWeek) - 1));
                    }
                    DateTime today = now;
                    now = now.AddMonths(-((int)now.Month - 1));

                    var weekly = (from wt in db.statsWeeklies
                                  where wt.zone1 == zone._zone && wt.date >= now && wt.date < today
                                  orderby wt.date descending
                                  select wt);

                    MemoryStream stream = new MemoryStream();
                    try
                    {
                        foreach (Data.DB.statsWeekly week in weekly)
                        {
                            BinaryWriter bw = new BinaryWriter(stream);
                            bw.Write(week.players[0].alias1.name.ToCharArray());
                            bw.Write((byte)0);

                            Data.DB.squad squad     = week.players[0].squad1;
                            string        squadname = "";
                            if (squad != null)
                            {
                                squadname = squad.name;
                            }

                            bw.Write(squadname.ToCharArray());
                            bw.Write((byte)0);

                            bw.Write((short)2);
                            bw.Write(week.vehicleDeaths);
                            bw.Write(week.vehicleKills);
                            bw.Write(week.killPoints);
                            bw.Write(week.deathPoints);
                            bw.Write(week.assistPoints);
                            bw.Write(week.bonusPoints);
                            bw.Write(week.kills);
                            bw.Write(week.deaths);
                            bw.Write((int)0);
                            bw.Write(week.playSeconds);
                        }
                    }
                    catch (Exception e)
                    {
                        Log.write(TLog.Warning, "WriteElementHistoryWeekly " + e);
                    }

                    SC_PlayerStatsResponse <Zone> response = new SC_PlayerStatsResponse <Zone>();

                    response.player  = pkt.player;
                    response.type    = CS_PlayerStatsRequest <Zone> .ChartType.ScoreHistoryWeekly;
                    response.columns = "ScoreHistory Weekly Score,Name,Squad";
                    response.data    = stream.ToArray();

                    zone._client.sendReliable(response, 1);
                }
                break;

                case CS_PlayerStatsRequest <Zone> .ChartType.ScoreHistoryMonthly:
                {
                    Data.DB.alias  getAlias  = db.alias.FirstOrDefault(a => a.name.Equals(pkt.options));
                    Data.DB.player getPlayer = db.players.FirstOrDefault(p => p.alias1 == getAlias && p.zone == zone._zone.id);
                    if (getPlayer == null)
                    {
                        return;
                    }

                    //Lets give them a year's worth
                    DateTime now = DateTime.Today;
                    if (((int)now.Day - 1) > 1)
                    {
                        now = now.AddDays(-(((int)now.Day) - 1));
                    }
                    DateTime today = now;
                    now = now.AddMonths(-((int)now.Month - 1));

                    var monthly = (from mt in db.statsMonthlies
                                   where mt.zone1 == zone._zone && mt.date >= now && mt.date < today
                                   orderby mt.date descending
                                   select mt);

                    MemoryStream stream = new MemoryStream();
                    try
                    {
                        foreach (Data.DB.statsMonthly month in monthly)
                        {
                            BinaryWriter bw = new BinaryWriter(stream);
                            bw.Write(month.players[0].alias1.name.ToCharArray());
                            bw.Write((byte)0);

                            Data.DB.squad squad     = month.players[0].squad1;
                            string        squadname = "";
                            if (squad != null)
                            {
                                squadname = squad.name;
                            }

                            bw.Write(squadname.ToCharArray());
                            bw.Write((byte)0);

                            bw.Write((short)2);
                            bw.Write(month.vehicleDeaths);
                            bw.Write(month.vehicleKills);
                            bw.Write(month.killPoints);
                            bw.Write(month.deathPoints);
                            bw.Write(month.assistPoints);
                            bw.Write(month.bonusPoints);
                            bw.Write(month.kills);
                            bw.Write(month.deaths);
                            bw.Write((int)0);
                            bw.Write(month.playSeconds);
                        }
                    }
                    catch (Exception e)
                    {
                        Log.write(TLog.Warning, "WriteElementHistoryMonthly " + e);
                    }

                    SC_PlayerStatsResponse <Zone> response = new SC_PlayerStatsResponse <Zone>();

                    response.player  = pkt.player;
                    response.type    = CS_PlayerStatsRequest <Zone> .ChartType.ScoreHistoryMonthly;
                    response.columns = "ScoreHistory Monthly Score,Name,Squad";
                    response.data    = stream.ToArray();

                    zone._client.sendReliable(response, 1);
                }
                break;

                case CS_PlayerStatsRequest <Zone> .ChartType.ScoreHistoryYearly:
                {
                    Data.DB.alias  getAlias  = db.alias.FirstOrDefault(a => a.name.Equals(pkt.options));
                    Data.DB.player getPlayer = db.players.FirstOrDefault(p => p.alias1 == getAlias && p.zone == zone._zone.id);
                    if (getPlayer == null)
                    {
                        return;
                    }

                    //Lets give them a year's worth
                    DateTime now = DateTime.Today;
                    if (((int)now.Day - 1) > 1)
                    {
                        now = now.AddDays(-(((int)now.Day) - 1));
                    }
                    DateTime today = now;
                    now = now.AddMonths(-((int)now.Month - 1));

                    var yearly = (from yt in db.statsYearlies
                                  where yt.zone1 == zone._zone && yt.date >= now && yt.date < today
                                  orderby yt.date descending
                                  select yt);

                    MemoryStream stream = new MemoryStream();
                    try
                    {
                        foreach (Data.DB.statsYearly year in yearly)
                        {
                            BinaryWriter bw = new BinaryWriter(stream);
                            bw.Write(year.players[0].alias1.name.ToCharArray());
                            bw.Write((byte)0);

                            Data.DB.squad squad     = year.players[0].squad1;
                            string        squadname = "";
                            if (squad != null)
                            {
                                squadname = squad.name;
                            }

                            bw.Write(squadname.ToCharArray());
                            bw.Write((byte)0);

                            bw.Write((short)2);
                            bw.Write(year.vehicleDeaths);
                            bw.Write(year.vehicleKills);
                            bw.Write(year.killPoints);
                            bw.Write(year.deathPoints);
                            bw.Write(year.assistPoints);
                            bw.Write(year.bonusPoints);
                            bw.Write(year.kills);
                            bw.Write(year.deaths);
                            bw.Write((int)0);
                            bw.Write(year.playSeconds);
                        }
                    }
                    catch (Exception e)
                    {
                        Log.write(TLog.Warning, "WriteElementHistoryYearly " + e);
                    }

                    SC_PlayerStatsResponse <Zone> response = new SC_PlayerStatsResponse <Zone>();

                    response.player  = pkt.player;
                    response.type    = CS_PlayerStatsRequest <Zone> .ChartType.ScoreHistoryYearly;
                    response.columns = "ScoreHistory Yearly Score,Name,Squad";
                    response.data    = stream.ToArray();

                    zone._client.sendReliable(response, 1);
                }
                break;
                }
            }
        }