public static void OnCityInfoResponse(ProcessedPacket Packet) { byte NumCities = (byte)Packet.ReadByte(); if (Packet.DecryptedLength > 1) { lock (NetworkFacade.Cities) { for (int i = 0; i < NumCities; i++) { string Name = Packet.ReadString(); string Description = Packet.ReadString(); string IP = Packet.ReadString(); int Port = Packet.ReadInt32(); byte StatusByte = (byte)Packet.ReadByte(); CityInfoStatus Status = (CityInfoStatus)StatusByte; ulong Thumbnail = Packet.ReadUInt64(); string UUID = Packet.ReadString(); ulong Map = Packet.ReadUInt64(); CityInfo Info = new CityInfo(false); Info.Name = Name; Info.Description = Description; Info.Thumbnail = Thumbnail; Info.UUID = UUID; Info.Map = Map; Info.IP = IP; Info.Port = Port; Info.Online = true; Info.Status = Status; NetworkFacade.Cities.Add(Info); } } } }
/// <summary> /// New city server came online! /// </summary> public static void OnNewCityServer(NetworkClient Client, ProcessedPacket Packet) { lock (NetworkFacade.Cities) { CityInfo Info = new CityInfo(false); Info.Name = Packet.ReadString(); Info.Description = Packet.ReadString(); Info.IP = Packet.ReadString(); Info.Port = Packet.ReadInt32(); Info.Status = (CityInfoStatus)Packet.ReadByte(); Info.Thumbnail = Packet.ReadUInt64(); Info.UUID = Packet.ReadString(); Info.Map = Packet.ReadUInt64(); NetworkFacade.Cities.Add(Info); } }
/// <summary> /// A player joined a session (game) in progress. /// </summary> public static Sim OnPlayerJoinedSession(ProcessedPacket Packet) { Sim Avatar = new Sim(Packet.ReadPascalString()); Avatar.Name = Packet.ReadPascalString(); Avatar.Sex = Packet.ReadPascalString(); Avatar.Description = Packet.ReadPascalString(); Avatar.HeadOutfitID = Packet.ReadUInt64(); Avatar.BodyOutfitID = Packet.ReadUInt64(); Avatar.Appearance = (AppearanceType)Packet.ReadInt32(); lock (NetworkFacade.AvatarsInSession) { NetworkFacade.AvatarsInSession.Add(Avatar); } return(Avatar); }
/// <summary> /// A cityserver logged in! /// </summary> public static void HandleCityServerLogin(NetworkClient Client, ProcessedPacket P) { Logger.LogInfo("CityServer logged in!\r\n"); string Name = P.ReadString(); string Description = P.ReadString(); string IP = P.ReadString(); int Port = P.ReadInt32(); CityInfoStatus Status = (CityInfoStatus)P.ReadByte(); ulong Thumbnail = P.ReadUInt64(); string UUID = P.ReadString(); ulong Map = P.ReadUInt64(); CityInfo Info = new CityInfo(true); Info.Name = Name; Info.Description = Description; Info.IP = IP; Info.Port = Port; Info.Status = Status; Info.Thumbnail = Thumbnail; Info.UUID = UUID; Info.Map = Map; Info.Client = Client; Info.Online = true; NetworkFacade.CServerListener.CityServers.Add(Info); NetworkFacade.CServerListener.PotentialLogins.TryTake(out Client); NetworkClient[] Clients = new NetworkClient[NetworkFacade.ClientListener.Clients.Count]; NetworkFacade.ClientListener.Clients.CopyTo(Clients, 0); PacketStream ClientPacket = new PacketStream((byte)PacketType.NEW_CITY_SERVER, 0); ClientPacket.WriteString(Name); ClientPacket.WriteString(Description); ClientPacket.WriteString(IP); ClientPacket.WriteInt32(Port); ClientPacket.WriteByte((byte)Status); ClientPacket.WriteUInt64(Thumbnail); ClientPacket.WriteString(UUID); ClientPacket.WriteUInt64(Map); foreach(NetworkClient Receiver in Clients) Receiver.SendEncrypted((byte)PacketType.NEW_CITY_SERVER, ClientPacket.ToArray()); }
/// <summary> /// A cityserver logged in! /// </summary> public static void HandleCityServerLogin(NetworkClient Client, ProcessedPacket P) { CityServerClient CityClient = (CityServerClient)Client; Logger.LogInfo("CityServer logged in!\r\n"); string Name = P.ReadString(); string Description = P.ReadString(); string IP = P.ReadString(); int Port = P.ReadInt32(); CityInfoStatus Status = (CityInfoStatus)P.ReadByte(); ulong Thumbnail = P.ReadUInt64(); string UUID = P.ReadString(); ulong Map = P.ReadUInt64(); CityInfo Info = new CityInfo(Name, Description, Thumbnail, UUID, Map, IP, Port); Info.Status = Status; CityClient.ServerInfo = Info; //Client instance changed, so update it... NetworkFacade.CServerListener.UpdateClient(CityClient); }
/// <summary> /// A player joined a session (game) in progress. /// </summary> public static LotTileEntry OnPlayerJoinedSession(NetworkClient Client, ProcessedPacket Packet) { LotTileEntry TileEntry = new LotTileEntry(0, "", 0, 0, 0, 0); UISim Avatar = new UISim(Packet.ReadString()); Avatar.Name = Packet.ReadString(); Avatar.Sex = Packet.ReadString(); Avatar.Description = Packet.ReadString(); Avatar.HeadOutfitID = Packet.ReadUInt64(); Avatar.BodyOutfitID = Packet.ReadUInt64(); Avatar.Avatar.Appearance = (AppearanceType)Packet.ReadInt32(); byte HasHouse = (byte)Packet.ReadByte(); if (HasHouse != 0) { TileEntry = new LotTileEntry(Packet.ReadInt32(), Packet.ReadString(), (short)Packet.ReadUInt16(), (short)Packet.ReadUInt16(), (byte)Packet.ReadByte(), Packet.ReadInt32()); Avatar.LotID = TileEntry.lotid; Avatar.HouseX = TileEntry.x; Avatar.HouseY = TileEntry.y; LotTileEntry[] TileEntries = new LotTileEntry[GameFacade.CDataRetriever.LotTileData.Length + 1]; TileEntries[0] = TileEntry; GameFacade.CDataRetriever.LotTileData.CopyTo(TileEntries, 1); } lock (NetworkFacade.AvatarsInSession) { NetworkFacade.AvatarsInSession.Add(Avatar); } return(TileEntry); }
/// <summary> /// LoginServer sent information about the player's characters. /// </summary> /// <param name="Packet">The packet that was received.</param> public static void OnCharacterInfoResponse(ProcessedPacket Packet, NetworkClient Client) { //If the decrypted length == 1, it means that there were 0 //characters that needed to be updated, or that the user //hasn't created any characters on his/her account yet. //Since the Packet.Length property is equal to the length //of the encrypted data, it cannot be used to get the length //of the decrypted data. if (Packet.DecryptedLength > 1) { byte NumCharacters = (byte)Packet.ReadByte(); List<Sim> FreshSims = new List<Sim>(); for (int i = 0; i < NumCharacters; i++) { int CharacterID = Packet.ReadInt32(); Sim FreshSim = new Sim(Packet.ReadString()); FreshSim.CharacterID = CharacterID; FreshSim.Timestamp = Packet.ReadString(); FreshSim.Name = Packet.ReadString(); FreshSim.Sex = Packet.ReadString(); FreshSim.Description = Packet.ReadString(); FreshSim.HeadOutfitID = Packet.ReadUInt64(); FreshSim.BodyOutfitID = Packet.ReadUInt64(); FreshSim.AppearanceType = (SimsLib.ThreeD.AppearanceType)Packet.ReadByte(); FreshSim.ResidingCity = new CityInfo(Packet.ReadString(), "", Packet.ReadUInt64(), Packet.ReadString(), Packet.ReadUInt64(), Packet.ReadString(), Packet.ReadInt32()); FreshSims.Add(FreshSim); } NetworkFacade.Avatars = FreshSims; Cache.CacheSims(FreshSims); } PacketStream CityInfoRequest = new PacketStream(0x06, 0); CityInfoRequest.WriteByte(0x00); //Dummy Client.SendEncrypted((byte)PacketType.CITY_LIST, CityInfoRequest.ToArray()); }
public static void OnCityInfoResponse(ProcessedPacket Packet) { byte NumCities = (byte)Packet.ReadByte(); if (Packet.DecryptedLength > 1) { lock (NetworkFacade.Cities) { for (int i = 0; i < NumCities; i++) { string Name = Packet.ReadString(); string Description = Packet.ReadString(); string IP = Packet.ReadString(); int Port = Packet.ReadInt32(); byte StatusByte = (byte)Packet.ReadByte(); CityInfoStatus Status = (CityInfoStatus)StatusByte; ulong Thumbnail = Packet.ReadUInt64(); string UUID = Packet.ReadString(); ulong Map = Packet.ReadUInt64(); CityInfo Info = new CityInfo(false); Info.Name = Name; Info.Description = Description; Info.Thumbnail = Thumbnail; Info.UUID = UUID; Info.Map = Map; Info.IP = IP; Info.Port = Port; Info.Online = true; Info.Status = Status; NetworkFacade.Cities.Add(Info); } } } }
/// <summary> /// New city server came online! /// </summary> public static void OnNewCityServer(NetworkClient Client, ProcessedPacket Packet) { lock (NetworkFacade.Cities) { CityInfo Info = new CityInfo(false); Info.Name = Packet.ReadString(); Info.Description = Packet.ReadString(); Info.IP = Packet.ReadString(); Info.Port = Packet.ReadInt32(); Info.Status = (CityInfoStatus)Packet.ReadByte(); Info.Thumbnail = Packet.ReadUInt64(); Info.UUID = Packet.ReadString(); Info.Map = Packet.ReadUInt64(); NetworkFacade.Cities.Add(Info); } }
/// <summary> /// LoginServer sent information about the player's characters. /// </summary> /// <param name="Packet">The packet that was received.</param> public static void OnCharacterInfoResponse(ProcessedPacket Packet, NetworkClient Client) { byte NumCharacters = (byte)Packet.ReadByte(); byte NewCharacters = (byte)Packet.ReadByte(); List <UISim> FreshSims = new List <UISim>(); for (int i = 0; i < NewCharacters; i++) { int CharacterID = Packet.ReadInt32(); UISim FreshSim = new UISim(Packet.ReadString(), false); FreshSim.CharacterID = CharacterID; FreshSim.Timestamp = Packet.ReadString(); FreshSim.Name = Packet.ReadString(); FreshSim.Sex = Packet.ReadString(); FreshSim.Description = Packet.ReadString(); FreshSim.HeadOutfitID = Packet.ReadUInt64(); FreshSim.BodyOutfitID = Packet.ReadUInt64(); FreshSim.Avatar.Appearance = (AppearanceType)Packet.ReadByte(); FreshSim.ResidingCity = new CityInfo(false); FreshSim.ResidingCity.Name = Packet.ReadString(); FreshSim.ResidingCity.Thumbnail = Packet.ReadUInt64(); FreshSim.ResidingCity.UUID = Packet.ReadString(); FreshSim.ResidingCity.Map = Packet.ReadUInt64(); FreshSim.ResidingCity.IP = Packet.ReadString(); FreshSim.ResidingCity.Port = Packet.ReadInt32(); FreshSims.Add(FreshSim); } lock (NetworkFacade.Avatars) { if ((NumCharacters < 3) && (NewCharacters > 0)) { FreshSims = Cache.LoadCachedSims(FreshSims); NetworkFacade.Avatars = FreshSims; Cache.CacheSims(FreshSims); } if (NewCharacters == 0 && NumCharacters > 0) { NetworkFacade.Avatars = Cache.LoadAllSims(); } else if (NewCharacters == 3 && NumCharacters == 3) { NetworkFacade.Avatars = FreshSims; Cache.CacheSims(FreshSims); } else if (NewCharacters == 0 && NumCharacters == 0) { //Make sure if sims existed in the cache, they are deleted (because they didn't exist in DB). Cache.DeleteCache(); } else if (NumCharacters == 3 && NewCharacters == 3) { NetworkFacade.Avatars = FreshSims; } } PacketStream CityInfoRequest = new PacketStream(0x06, 0); CityInfoRequest.WriteByte(0x00); //Dummy Client.SendEncrypted((byte)PacketType.CITY_LIST, CityInfoRequest.ToArray()); }
/// <summary> /// A player joined a session (game) in progress. /// </summary> public static LotTileEntry OnPlayerJoinedSession(NetworkClient Client, ProcessedPacket Packet) { LotTileEntry TileEntry = new LotTileEntry(0, "", 0, 0, 0, 0); UISim Avatar = new UISim(Packet.ReadString()); Avatar.Name = Packet.ReadString(); Avatar.Sex = Packet.ReadString(); Avatar.Description = Packet.ReadString(); Avatar.HeadOutfitID = Packet.ReadUInt64(); Avatar.BodyOutfitID = Packet.ReadUInt64(); Avatar.Avatar.Appearance = (AppearanceType)Packet.ReadInt32(); byte HasHouse = (byte)Packet.ReadByte(); if (HasHouse != 0) { TileEntry = new LotTileEntry(Packet.ReadInt32(), Packet.ReadString(), (short)Packet.ReadUInt16(), (short)Packet.ReadUInt16(), (byte)Packet.ReadByte(), Packet.ReadInt32()); Avatar.LotID = TileEntry.lotid; Avatar.HouseX = TileEntry.x; Avatar.HouseY = TileEntry.y; LotTileEntry[] TileEntries = new LotTileEntry[TSOClient.Code.GameFacade.CDataRetriever.LotTileData.Length + 1]; TileEntries[0] = TileEntry; TSOClient.Code.GameFacade.CDataRetriever.LotTileData.CopyTo(TileEntries, 1); } lock (NetworkFacade.AvatarsInSession) { NetworkFacade.AvatarsInSession.Add(Avatar); } return TileEntry; }
/// <summary> /// Client created a character! /// </summary> public static void HandleCharacterCreate(NetworkClient Client, ProcessedPacket P) { Logger.LogInfo("Received CharacterCreate!"); string AccountName = SanitizeAccount(P.ReadString()); //Need to be variable length, because the success packet contains a token. PacketStream CCStatusPacket = new PacketStream((byte)PacketType.CHARACTER_CREATION_STATUS, 0); using (var db = DataAccess.Get()) { Account Acc = db.Accounts.GetByUsername(AccountName); if (Acc.NumCharacters >= 3) { CCStatusPacket.WriteByte((int)LoginDataModel.Entities.CharacterCreationStatus.ExceededCharacterLimit); Client.SendEncrypted(CCStatusPacket.PacketID, CCStatusPacket.ToArray()); return; } //TODO: Send GUID to client... var Char = new Character(); string LastCached = P.ReadString(); if (LastCached == string.Empty) { //TODO: Proper error... CCStatusPacket.WriteByte((int)LoginDataModel.Entities.CharacterCreationStatus.NameAlreadyExisted); Client.SendEncrypted(CCStatusPacket.PacketID, CCStatusPacket.ToArray()); return; } Char.LastCached = ProtoHelpers.ParseDateTime(LastCached); Char.Name = P.ReadString(); Char.Sex = P.ReadString(); Char.Description = P.ReadString(); Char.GUID = Guid.NewGuid(); Char.HeadOutfitID = (long)P.ReadUInt64(); Char.BodyOutfitID = (long)P.ReadUInt64(); Char.AccountID = Acc.AccountID; Char.AppearanceType = P.ReadByte(); Char.CityName = P.ReadString(); Char.CityThumb = (long)P.ReadUInt64(); Char.City = P.ReadString(); Char.CityMap = (long)P.ReadUInt64(); Char.CityIp = P.ReadString(); Char.CityPort = P.ReadInt32(); Char.Money = NetworkFacade.INITIAL_MONEY; //These are going into DB, so be nazi. Sieg heil! if (Char.Name == string.Empty || Char.Sex == string.Empty || Char.Description == string.Empty) { CCStatusPacket.WriteByte((int)LoginDataModel.Entities.CharacterCreationStatus.NameAlreadyExisted); Client.SendEncrypted(CCStatusPacket.PacketID, CCStatusPacket.ToArray()); return; } var status = db.Characters.CreateCharacter(Char); switch (status) { case LoginDataModel.Entities.CharacterCreationStatus.NameAlreadyExisted: CCStatusPacket.WriteByte((int)LoginDataModel.Entities.CharacterCreationStatus.NameAlreadyExisted); Client.SendEncrypted(CCStatusPacket.PacketID, CCStatusPacket.ToArray()); break; case LoginDataModel.Entities.CharacterCreationStatus.NameTooLong: CCStatusPacket.WriteByte((int)LoginDataModel.Entities.CharacterCreationStatus.NameTooLong); Client.SendEncrypted(CCStatusPacket.PacketID, CCStatusPacket.ToArray()); break; case LoginDataModel.Entities.CharacterCreationStatus.Success: Guid Token = Guid.NewGuid(); //This actually updates the record, not sure how. Acc.NumCharacters++; //THIS NEEDS TO HAPPEN FIRST FOR CITY SERVER AUTHENTICATION TO WORK! CityInfo CServer = NetworkFacade.CServerListener.GetCityServer(Char.City); //Just in case... if (CServer != null) { PacketStream CServerPacket = new PacketStream(0x01, 0); CServerPacket.WriteHeader(); ushort PacketLength = (ushort)(PacketHeaders.UNENCRYPTED + 1 + 4 + (Client.RemoteIP.Length + 1) + 4 + (Char.GUID.ToString().Length + 1) + (Token.ToString().Length + 1)); CServerPacket.WriteUInt16(PacketLength); CServerPacket.WriteByte(1); //CharacterCreate = true CServerPacket.WriteInt32(Acc.AccountID); CServerPacket.WriteString(Client.RemoteIP); CServerPacket.WriteInt32(Client.RemotePort); CServerPacket.WriteString(Char.GUID.ToString()); CServerPacket.WriteString(Token.ToString("")); CServer.Client.Send(CServerPacket.ToArray()); } CCStatusPacket.WriteByte((int)LoginDataModel.Entities.CharacterCreationStatus.Success); CCStatusPacket.WriteString(Char.GUID.ToString()); CCStatusPacket.WriteString(Token.ToString()); Client.SendEncrypted(CCStatusPacket.PacketID, CCStatusPacket.ToArray()); break; } } }
/// <summary> /// Client wanted to create a new character. /// </summary> public static void HandleCharacterCreate(NetworkClient Client, ProcessedPacket P) { try { Logger.LogInfo("Received CharacterCreate!"); bool ClientAuthenticated = false; byte AccountStrLength = (byte)P.ReadByte(); byte[] AccountNameBuf = new byte[AccountStrLength]; if (P.BufferLength >= AccountStrLength) { P.Read(AccountNameBuf, 0, AccountStrLength); string AccountName = Encoding.ASCII.GetString(AccountNameBuf); } else { return; } using (DataAccess db = DataAccess.Get()) { //No need to check for empty string here, because all it will do is have ClientAuthenticated be false string Token = P.ReadString(); string GUID = ""; int AccountID = 0; ClientToken TokenToRemove = NetworkFacade.GetClientToken(Client.RemoteIP); //Just in case... if (TokenToRemove != null) { if (TokenToRemove.Token.Equals(Token, StringComparison.CurrentCultureIgnoreCase)) { PacketStream SuccessPacket = new PacketStream((byte)PacketType.CHARACTER_CREATE_CITY, 0); SuccessPacket.WriteByte((byte)CityDataModel.Entities.CharacterCreationStatus.Success); House[] Houses = NetworkFacade.CurrentSession.GetHousesInSession(); SuccessPacket.WriteUInt16((ushort)Houses.Length); //Ho, ho, ho... foreach (House Ho in Houses) { SuccessPacket.WriteInt32(Ho.HouseID); SuccessPacket.WriteString(Ho.Name); SuccessPacket.WriteUInt16((ushort)Ho.X); SuccessPacket.WriteUInt16((ushort)Ho.Y); SuccessPacket.WriteByte((byte)Ho.Flags); //Might have to save this as unsigned in DB? SuccessPacket.WriteInt32(Ho.Cost); } Client.SendEncrypted((byte)PacketType.CHARACTER_CREATE_CITY, SuccessPacket.ToArray()); ClientAuthenticated = true; GUID = TokenToRemove.CharacterGUID; AccountID = TokenToRemove.AccountID; Sim Char = new Sim(new Guid(GUID)); Char.Timestamp = P.ReadString(); Char.Name = P.ReadString(); Char.Sex = P.ReadString(); Char.Description = P.ReadString(); Char.HeadOutfitID = P.ReadUInt64(); Char.BodyOutfitID = P.ReadUInt64(); Char.Appearance = (AppearanceType)P.ReadByte(); Char.CreatedThisSession = true; //These are going into DB, so be nazi. Sieg heil! if (Char.Timestamp == string.Empty || Char.Name == string.Empty || Char.Sex == string.Empty || Char.Description == string.Empty) { //TODO: Tell loginserver to clean up DB? ClientAuthenticated = false; } var characterModel = new Character(); characterModel.Name = Char.Name; characterModel.Sex = Char.Sex; characterModel.Description = Char.Description; characterModel.LastCached = ProtoHelpers.ParseDateTime(Char.Timestamp); characterModel.GUID = Char.GUID; characterModel.HeadOutfitID = (long)Char.HeadOutfitID; characterModel.BodyOutfitID = (long)Char.BodyOutfitID; characterModel.AccountID = AccountID; characterModel.AppearanceType = (int)Char.Appearance; characterModel.Money = NetworkFacade.INITIAL_MONEY; NetworkFacade.CurrentSession.AddPlayer(Client, characterModel); var status = db.Characters.CreateCharacter(characterModel); } } NetworkFacade.TransferringClients.TryRemove(out TokenToRemove); } //Invalid token, should never occur... if (!ClientAuthenticated) { NetworkFacade.CurrentSession.RemovePlayer(Client); PacketStream FailPacket = new PacketStream((byte)PacketType.CHARACTER_CREATE_CITY_FAILED, (int)(PacketHeaders.ENCRYPTED + 1)); FailPacket.WriteByte((byte)CityDataModel.Entities.CharacterCreationStatus.GeneralError); Client.SendEncrypted((byte)PacketType.CHARACTER_CREATE_CITY_FAILED, FailPacket.ToArray()); } } catch (Exception E) { Debug.WriteLine("Exception in HandleCharacterCreate: " + E.ToString()); Logger.LogDebug("Exception in HandleCharacterCreate: " + E.ToString()); PacketStream FailPacket = new PacketStream((byte)PacketType.CHARACTER_CREATE_CITY_FAILED, (int)(PacketHeaders.ENCRYPTED + 1)); FailPacket.WriteByte((byte)CityDataModel.Entities.CharacterCreationStatus.GeneralError); Client.SendEncrypted((byte)PacketType.CHARACTER_CREATE_CITY_FAILED, FailPacket.ToArray()); } }
/// <summary> /// LoginServer sent information about the player's characters. /// </summary> /// <param name="Packet">The packet that was received.</param> public static void OnCharacterInfoResponse(ProcessedPacket Packet, NetworkClient Client) { byte NumCharacters = (byte)Packet.ReadByte(); byte NewCharacters = (byte)Packet.ReadByte(); List<UISim> FreshSims = new List<UISim>(); for (int i = 0; i < NewCharacters; i++) { int CharacterID = Packet.ReadInt32(); UISim FreshSim = new UISim(Packet.ReadString(), false); FreshSim.CharacterID = CharacterID; FreshSim.Timestamp = Packet.ReadString(); FreshSim.Name = Packet.ReadString(); FreshSim.Sex = Packet.ReadString(); FreshSim.Description = Packet.ReadString(); FreshSim.HeadOutfitID = Packet.ReadUInt64(); FreshSim.BodyOutfitID = Packet.ReadUInt64(); FreshSim.Avatar.Appearance = (AppearanceType)Packet.ReadByte(); FreshSim.ResidingCity = new CityInfo(false); FreshSim.ResidingCity.Name = Packet.ReadString(); FreshSim.ResidingCity.Thumbnail = Packet.ReadUInt64(); FreshSim.ResidingCity.UUID = Packet.ReadString(); FreshSim.ResidingCity.Map = Packet.ReadUInt64(); FreshSim.ResidingCity.IP = Packet.ReadString(); FreshSim.ResidingCity.Port = Packet.ReadInt32(); FreshSims.Add(FreshSim); } lock (NetworkFacade.Avatars) { if ((NumCharacters < 3) && (NewCharacters > 0)) { FreshSims = Cache.LoadCachedSims(FreshSims); NetworkFacade.Avatars = FreshSims; Cache.CacheSims(FreshSims); } if (NewCharacters == 0 && NumCharacters > 0) NetworkFacade.Avatars = Cache.LoadAllSims(); else if (NewCharacters == 3 && NumCharacters == 3) { NetworkFacade.Avatars = FreshSims; Cache.CacheSims(FreshSims); } else if (NewCharacters == 0 && NumCharacters == 0) { //Make sure if sims existed in the cache, they are deleted (because they didn't exist in DB). Cache.DeleteCache(); } else if (NumCharacters == 3 && NewCharacters == 3) { NetworkFacade.Avatars = FreshSims; } } PacketStream CityInfoRequest = new PacketStream(0x06, 0); CityInfoRequest.WriteByte(0x00); //Dummy Client.SendEncrypted((byte)PacketType.CITY_LIST, CityInfoRequest.ToArray()); }
public static void OnCityInfoResponse(ProcessedPacket Packet) { byte NumCities = (byte)Packet.ReadByte(); if (Packet.DecryptedLength > 1) { for (int i = 0; i < NumCities; i++) { string Name = Packet.ReadString(); string Description = Packet.ReadString(); string IP = Packet.ReadString(); int Port = Packet.ReadInt32(); byte StatusByte = (byte)Packet.ReadByte(); CityInfoStatus Status = (CityInfoStatus)StatusByte; ulong Thumbnail = Packet.ReadUInt64(); string UUID = Packet.ReadString(); ulong Map = Packet.ReadUInt64(); CityInfo Info = new CityInfo(Name, Description, Thumbnail, UUID, Map, IP, Port); Info.Online = true; Info.Status = Status; NetworkFacade.Cities.Add(Info); } } }
public static void HandleCharacterCreate(NetworkClient Client, ProcessedPacket P) { try { Logger.LogInfo("Received CharacterCreate!"); bool ClientAuthenticated = false; byte AccountStrLength = (byte)P.ReadByte(); byte[] AccountNameBuf = new byte[AccountStrLength]; P.Read(AccountNameBuf, 0, AccountStrLength); string AccountName = Encoding.ASCII.GetString(AccountNameBuf); byte HashLength = (byte)P.ReadByte(); byte[] HashBuf = new byte[HashLength]; P.Read(HashBuf, 0, HashLength); using (DataAccess db = DataAccess.Get()) { Client.ClientEncryptor = new ARC4Encryptor(Convert.ToBase64String(HashBuf)); Client.ClientEncryptor.Username = AccountName; string Token = P.ReadString(); string GUID = ""; int AccountID = 0; foreach (ClientToken CToken in NetworkFacade.TransferringClients.GetList()) { if (CToken.ClientIP == Client.RemoteIP) { if (CToken.Token == Token) { PacketStream SuccessPacket = new PacketStream((byte)PacketType.CHARACTER_CREATE_CITY, (int)(PacketHeaders.ENCRYPTED + 1)); SuccessPacket.WriteByte((byte)CityDataModel.Entities.CharacterCreationStatus.Success); Client.SendEncrypted((byte)PacketType.CHARACTER_CREATE_CITY, SuccessPacket.ToArray()); ClientAuthenticated = true; GUID = CToken.CharacterGUID; AccountID = CToken.AccountID; } break; } } Sim Char = new Sim(new Guid(GUID)); Char.Timestamp = P.ReadPascalString(); Char.Name = P.ReadPascalString(); Char.Sex = P.ReadPascalString(); Char.Description = P.ReadPascalString(); Char.HeadOutfitID = P.ReadUInt64(); Char.BodyOutfitID = P.ReadUInt64(); Char.Appearance = (AppearanceType)P.ReadByte(); Char.CreatedThisSession = true; var characterModel = new Character(); characterModel.Name = Char.Name; characterModel.Sex = Char.Sex; characterModel.Description = Char.Description; characterModel.LastCached = Char.Timestamp; characterModel.GUID = Char.GUID; characterModel.HeadOutfitID = (long)Char.HeadOutfitID; characterModel.BodyOutfitID = (long)Char.BodyOutfitID; characterModel.AccountID = AccountID; characterModel.AppearanceType = (int)Char.Appearance; var status = db.Characters.CreateCharacter(characterModel); } //Invalid token, should never occur... if (!ClientAuthenticated) { PacketStream SuccessPacket = new PacketStream(0x65, (int)(PacketHeaders.ENCRYPTED + 1)); SuccessPacket.WriteByte((byte)CityDataModel.Entities.CharacterCreationStatus.GeneralError); Client.SendEncrypted(0x64, SuccessPacket.ToArray()); Client.Disconnect(); } } catch (Exception E) { Logger.LogDebug("Exception in HandleCharacterCreate: " + E.ToString()); } }
public static void HandleCharacterCreate(NetworkClient Client, ProcessedPacket P) { Logger.LogInfo("Received CharacterCreate!"); string AccountName = SanitizeAccount(P.ReadPascalString()); using (var db = DataAccess.Get()) { Account Acc = db.Accounts.GetByUsername(AccountName); //TODO: Send GUID to client... SimBase Char = new SimBase(Guid.NewGuid()); Char.Timestamp = P.ReadPascalString(); Char.Name = P.ReadPascalString(); Char.Sex = P.ReadPascalString(); Char.Description = P.ReadPascalString(); Char.HeadOutfitID = P.ReadUInt64(); Char.BodyOutfitID = P.ReadUInt64(); Char.Appearance = (AppearanceType)P.ReadByte(); Char.ResidingCity = new CityInfo(P.ReadPascalString(), "", P.ReadUInt64(), P.ReadPascalString(), P.ReadUInt64(), P.ReadPascalString(), P.ReadInt32()); Char.CreatedThisSession = true; var characterModel = new Character(); characterModel.Name = Char.Name; characterModel.Sex = Char.Sex; characterModel.Description = Char.Description; characterModel.LastCached = Char.Timestamp; characterModel.GUID = Char.GUID; characterModel.HeadOutfitID = (long)Char.HeadOutfitID; characterModel.BodyOutfitID = (long)Char.BodyOutfitID; characterModel.AccountID = Acc.AccountID; characterModel.AppearanceType = (int)Char.Appearance; characterModel.City = Char.ResidingCity.UUID; characterModel.CityName = Char.ResidingCity.Name; characterModel.CityThumb = (long)Char.ResidingCity.Thumbnail; characterModel.CityMap = (long)Char.ResidingCity.Map; characterModel.CityIp = Char.ResidingCity.IP; characterModel.CityPort = Char.ResidingCity.Port; var status = db.Characters.CreateCharacter(characterModel); //Need to be variable length, because the success packet contains a token. PacketStream CCStatusPacket = new PacketStream((byte)PacketType.CHARACTER_CREATION_STATUS, 0); switch (status) { case LoginDataModel.Entities.CharacterCreationStatus.NameAlreadyExisted: CCStatusPacket.WriteByte((int)LoginDataModel.Entities.CharacterCreationStatus.NameAlreadyExisted); Client.SendEncrypted(CCStatusPacket.PacketID, CCStatusPacket.ToArray()); break; case LoginDataModel.Entities.CharacterCreationStatus.ExceededCharacterLimit: CCStatusPacket.WriteByte((int)LoginDataModel.Entities.CharacterCreationStatus.ExceededCharacterLimit); Client.SendEncrypted(CCStatusPacket.PacketID, CCStatusPacket.ToArray()); break; case LoginDataModel.Entities.CharacterCreationStatus.Success: CCStatusPacket.WriteByte((int)LoginDataModel.Entities.CharacterCreationStatus.Success); CCStatusPacket.WritePascalString(Char.GUID.ToString()); Guid Token = Guid.NewGuid(); CCStatusPacket.WritePascalString(Token.ToString()); Client.SendEncrypted(CCStatusPacket.PacketID, CCStatusPacket.ToArray()); foreach (CityServerClient CServer in NetworkFacade.CServerListener.CityServers) { if (CServer.ServerInfo.UUID == Char.ResidingCity.UUID) { PacketStream CServerPacket = new PacketStream(0x01, 0); CServerPacket.WriteHeader(); ushort PacketLength = (ushort)(PacketHeaders.UNENCRYPTED + 4 + (Client.RemoteIP.Length + 1) + (Char.GUID.ToString().Length + 1) + (Token.ToString().Length + 1)); CServerPacket.WriteUInt16(PacketLength); CServerPacket.WriteInt32(Acc.AccountID); CServerPacket.WritePascalString(Client.RemoteIP); CServerPacket.WritePascalString(Char.GUID.ToString()); CServerPacket.WritePascalString(Token.ToString()); CServer.Send(CServerPacket.ToArray()); break; } } break; } } //Client was modified, so update it. NetworkFacade.ClientListener.UpdateClient(Client); }