예제 #1
0
        ///////////////////////////////////////////////////
        // Member Functions
        ///////////////////////////////////////////////////
        /// <summary>
        /// Generic constructor
        /// </summary>
        public Zone(Client client, DBServer server, Data.DB.zone zone)
        {
            _client = client;
            _server = server;
            _zone   = zone;

            _players = new Dictionary <int, Player>();
        }
예제 #2
0
        /// <summary>
        /// Handles a zone update packet and updates the database
        /// </summary>
        static public void Handle_CS_ZoneUpdate(CS_ZoneUpdate <Zone> pkt, Zone zone)
        {
            using (InfantryDataContext db = zone._server.getContext())
            {
                Data.DB.zone zEntry = db.zones.SingleOrDefault(z => z.id == zone._zone.id);
                if (zEntry != null)
                {
                    //Update the zone for our directory server
                    zEntry.name        = pkt.zoneName;
                    zEntry.description = pkt.zoneDescription;
                    zEntry.ip          = pkt.zoneIP;
                    zEntry.port        = pkt.zonePort;
                    zEntry.advanced    = Convert.ToInt16(pkt.zoneIsAdvanced);
                    zEntry.active      = pkt.zoneActive;

                    db.SubmitChanges();
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Handles the zone login request packet
        /// </summary>
        static public void Handle_CS_Auth(CS_Auth <Zone> pkt, Client <Zone> client)
        {               //Note the login request
            Log.write(TLog.Normal, "Login request from ({0}): {1} / {2}", client._ipe, pkt.zoneID, pkt.password);

            //Attempt to find the associated zone
            DBServer server = client._handler as DBServer;

            Data.DB.zone dbZone;

            using (InfantryDataContext db = server.getContext())
                dbZone = db.zones.SingleOrDefault(z => z.id == pkt.zoneID);

            //Does the zone exist?
            if (dbZone == null)
            {                   //Reply with failure
                SC_Auth <Zone> reply = new SC_Auth <Zone>();

                reply.result  = SC_Auth <Zone> .LoginResult.Failure;
                reply.message = "Invalid zone.";
                client.sendReliable(reply);
                return;
            }

            //Are the passwords a match?
            if (dbZone.password != pkt.password)
            {                   //Oh dear.
                SC_Auth <Zone> reply = new SC_Auth <Zone>();
                reply.result = SC_Auth <Zone> .LoginResult.BadCredentials;
                client.sendReliable(reply);
                return;
            }

            //Great! Escalate our client object to a zone
            Zone zone = new Zone(client, server, dbZone);

            client._obj = zone;

            server._zones.Add(zone);

            //Called on connection close / timeout
            zone._client.Destruct += delegate(NetworkClient nc)
            {
                zone.destroy();
            };

            //Success!
            SC_Auth <Zone> success = new SC_Auth <Zone>();

            success.result  = SC_Auth <Zone> .LoginResult.Success;
            success.message = dbZone.notice;

            client.sendReliable(success);

            using (InfantryDataContext db = zone._server.getContext())
            {
                //Update and activate the zone for our directory server
                //TODO: Don't know why it only works like this,
                //modifying dbZone and submitting changes doesn't reflect
                //in the database right away
                Data.DB.zone zoneentry = db.zones.SingleOrDefault(z => z.id == pkt.zoneID);
                zoneentry.name        = pkt.zoneName;
                zoneentry.description = pkt.zoneDescription;
                zoneentry.ip          = pkt.zoneIP;
                zoneentry.port        = pkt.zonePort;
                zoneentry.advanced    = Convert.ToInt16(pkt.zoneIsAdvanced);
                zoneentry.active      = 1;
                db.SubmitChanges();
            }
            Log.write("Successful login from {0} ({1})", dbZone.name, client._ipe);
        }