/// <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); }