Example #1
0
        /// <summary>
        /// Receives a stats response from the server and directs it to the appropriate player
        /// </summary>
        static public void Handle_SC_PlayerStatsResponse(SC_PlayerStatsResponse <Database> pkt, Database db)
        {               //Attempt to find the player in question
            Player player = db._server.getPlayer(pkt.player);

            if (player == null)
            {
                Log.write(TLog.Warning, "Received statistics response for unknown player instance.");
                return;
            }

            //Form and send a response
            SC_ScoreChart scores = new SC_ScoreChart();

            scores.type    = (Helpers.ChartType)pkt.type;
            scores.columns = pkt.columns;
            scores.data    = pkt.data;

            player._client.sendReliable(scores, 1);
        }
        /// <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;
                }
            }
        }
Example #3
0
        /// <summary>
        /// Creates a new packet based on the typeID and the received content
        /// inside the buffer. The user has to create an own implementation
        /// of this interface.
        /// </summary>
        public PacketBase createPacket(NetworkClient client, ushort typeID, byte[] buffer, int offset, int size)
        {               //Ready our packet base
            PacketBase packet = null;

            size--;

            //Was it a system packet?
            if (buffer[offset++] == 0)
            {
                //Yes, find the appropriate type
                return(createSystemPacket(typeID, buffer, offset, size));
            }

            //So what was the typeid?
            switch (typeID)
            {
            case SC_Auth <T> .TypeID:
                packet = new SC_Auth <T>(typeID, buffer, offset, size);
                break;

            case SC_PlayerLogin <T> .TypeID:
                packet = new SC_PlayerLogin <T>(typeID, buffer, offset, size);
                break;

            case SC_PlayerStatsResponse <T> .TypeID:
                packet = new SC_PlayerStatsResponse <T>(typeID, buffer, offset, size);
                break;

            case SC_Whisper <T> .TypeID:
                packet = new SC_Whisper <T>(typeID, buffer, offset, size);
                break;

            case SC_JoinChat <T> .TypeID:
                packet = new SC_JoinChat <T>(typeID, buffer, offset, size);
                break;

            case SC_LeaveChat <T> .TypeID:
                packet = new SC_LeaveChat <T>(typeID, buffer, offset, size);
                break;

            case SC_PrivateChat <T> .TypeID:
                packet = new SC_PrivateChat <T>(typeID, buffer, offset, size);
                break;

            case SC_Chat <T> .TypeID:
                packet = new SC_Chat <T>(typeID, buffer, offset, size);
                break;

            case SC_Zones <T> .TypeID:
                packet = new SC_Zones <T>(typeID, buffer, offset, size);
                break;

            case Disconnect <T> .TypeID:
                packet = new Disconnect <T>(typeID, buffer, offset, size);
                break;

            default:
                //An undefined packet.
                packet = new PacketDummy(typeID, buffer, offset, size);
                break;
            }

            return(packet);
        }