/// <summary>
        /// Handles a player update request
        /// </summary>
        static public void Handle_CS_SquadMatch(CS_SquadMatch <Zone> pkt, Zone zone)
        {
            using (InfantryDataContext db = zone._server.getContext())
            {
                Data.DB.squad winner = db.squads.FirstOrDefault(s => s.id == pkt.winner);
                Data.DB.squad loser  = db.squads.FirstOrDefault(s => s.id == pkt.loser);

                //Try to trick me, I dare you, do it.
                if (winner == null || loser == null)
                {
                    return;
                }

                Data.DB.squadstats wStats = db.squadstats.FirstOrDefault(s => s.squad == winner.id);
                Data.DB.squadstats lStats = db.squadstats.FirstOrDefault(s => s.squad == loser.id);

                //Again, try it!
                if (wStats == null || lStats == null)
                {
                    return;
                }

                //Update our winners!
                wStats.kills  += pkt.wStats.kills;
                wStats.deaths += pkt.wStats.deaths;
                wStats.points += pkt.wStats.points;
                wStats.wins++;

                //Update our losers!
                lStats.kills  += pkt.wStats.kills;
                lStats.deaths += pkt.wStats.deaths;
                lStats.points += pkt.wStats.points;
                lStats.losses++; //Sad trombone.....

                //Grab our associated match.
                Data.DB.squadmatch match = db.squadmatches.FirstOrDefault(m => m.squad1 == winner.id | m.squad2 == winner.id | m.squad1 == loser.id | m.squad2 == loser.id && m.winner == null);

                //Update it
                match.winner  = pkt.winner;
                match.loser   = pkt.loser;
                match.dateEnd = DateTime.Now;

                //Submit
                db.SubmitChanges();
            }
        }
예제 #2
0
파일: Database.cs 프로젝트: trjate/Infantry
        public void reportMatch(long winner, long loser, CS_SquadMatch <Database> .SquadStats wStats, CS_SquadMatch <Database> .SquadStats lStats)
        {
            if (_server.IsStandalone)
            {
                return;
            }

            //Create an update packet
            CS_SquadMatch <Database> upd = new CS_SquadMatch <Database>();

            upd.wStats = wStats;
            upd.lStats = wStats;
            upd.loser  = loser;
            upd.winner = winner;

            //All good!
            send(upd);
        }
예제 #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 CS_Auth <T> .TypeID:
                packet = new CS_Auth <T>(typeID, buffer, offset, size);
                break;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            return(packet);
        }