public static void Initialize() { s_Items = new List <_shard_item>(); using (var reader = Data.Globals.AccountDB.ExecuteReader("SELECT * FROM _Shard")) { while (reader.Read()) { _shard_item item = new _shard_item { ID = (int)reader["ID"], Name = (string)reader["Name"], ContentID = (byte)reader["ContentID"], CurrentUsers = 0, MaxUsers = (ushort)(short)reader["MaxUsers"], State = (byte)reader["State"], m_lock = new object() }; s_Items.Add(item); } } }
#pragma warning disable 1998, 4014 public async Task ProcessLoginResult(Services._shard_item shard, string id, string password) { using (var reader = await Data.Globals.AccountDB.ExecuteReaderAsync("exec _CertifyTB_User '{0}', '{1}'", id, password)) { await reader.ReadAsync(); Packet resp = new Packet(SCommon.Opcode.Gateway.Response.LOGIN); int type = await reader.GetFieldValueAsync <int>(0); switch (type) { case 0: { int sid = await reader.GetFieldValueAsync <int>(1); byte sec_content = await reader.GetFieldValueAsync <byte>(2); int session_id = -1; lock (shard.m_lock) { if (shard.CurrentUsers < shard.MaxUsers) { session_id = Services.Session.Generate(); } } if (session_id != -1) { Data.Globals.GlobalDB.ExecuteCommandAsync("INSERT INTO _ActiveSessions (UserSID, SessionID, Processed) VALUES ({0}, {1}, 0)", sid, session_id); resp.WriteByte(1); resp.WriteInt32(session_id); resp.WriteAscii(Data.Globals.GetConfigValue <string>("GameServerIPAddress")); resp.WriteUInt16(Data.Globals.GetConfigValue <ushort>("GameServerPort")); } else { resp.WriteByte(2); resp.WriteByte(5); } } break; case 1: { int sid = await reader.GetFieldValueAsync <int>(1); string ban_reason = await reader.GetFieldValueAsync <string>(2); DateTime ban_endTime = await reader.GetFieldValueAsync <DateTime>(3); resp.WriteByte(2); resp.WriteByte(2); resp.WriteByte(1); resp.WriteAscii(ban_reason); resp.WriteUInt16(ban_endTime.Year); resp.WriteUInt16(ban_endTime.Month); resp.WriteUInt16(ban_endTime.Day); resp.WriteUInt16(ban_endTime.Hour); resp.WriteUInt16(ban_endTime.Minute); resp.WriteUInt16(ban_endTime.Second); resp.WriteInt32(ban_endTime.Millisecond); } break; case 2: { resp.WriteByte(2); resp.WriteByte(1); if (Data.Globals.WrongPasswordTries.ContainsKey(id)) { var wrong = Data.Globals.WrongPasswordTries[id]; resp.WriteInt32(++wrong.Tries); wrong.LastTick = Environment.TickCount; Data.Globals.WrongPasswordTries[id] = wrong; } else { var wrong = new Data._wrongpass_item { LastTick = Environment.TickCount, Tries = 1 }; Data.Globals.WrongPasswordTries.Add(id, wrong); resp.WriteInt32(1); } resp.WriteInt32(Data.Globals.MAX_WRONG_PASSWORD); } break; case 3: { //already in game packet } break; } m_SocketContext.Send(resp); Disconnect(); } }