public static void SendPing(WorldClient client) { using (var packet = new Packet(SH2Type.Ping)) { client.SendPacket(packet); } }
public void AddClient(WorldClient client) { lock (clients) { clients.Add(client); } }
public static void CharacterSelectHandler(WorldClient client, Packet packet) { byte slot; if (!packet.TryReadByte(out slot) || slot > 10 || !client.Characters.ContainsKey(slot)) { Log.WriteLine(LogLevel.Warn, "{0} selected an invalid character.", client.Username); return; } WorldCharacter character; if (client.Characters.TryGetValue(slot, out character)) { //generate transfer ZoneConnection zone = Program.GetZoneByMap(character.Character.Map); if (zone != null) { client.Characters.Clear(); //we clear the other ones from memory client.Character = character; //only keep the one selected zone.SendTransferClientFromZone(client.AccountID, client.Username, client.Character.Character.Name, client.RandomID, client.Admin, client.Host); ClientManager.Instance.AddClientByName(client); //so we can look them up fast using charname later. SendZoneServerIP(client, zone); } else { Log.WriteLine(LogLevel.Warn, "Character tried to join unloaded map: {0}", character.Character.Map); SendConnectError(client, ConnectErrors.MapUnderMaintenance); } } }
public static void SendConnectError(WorldClient client, ConnectErrors error) { using (var packet = new Packet(SH4Type.ConnectError)) { packet.WriteUShort((ushort)error); client.SendPacket(packet); } }
public static void SendError(WorldClient client, ServerError error) { using (Packet pack = new Packet(SH3Type.Error)) { pack.WriteShort((byte)error); client.SendPacket(pack); } }
public void AddClientByName(WorldClient client) { if (client.Character != null && !clientsByName.ContainsKey(client.CharacterName)) { clientsByName.TryAdd(client.CharacterName, client); } else Log.WriteLine(LogLevel.Warn, "Trying to register client by name without having Character object."); }
public static void SendUnknown(WorldClient client) { using (var packet = new Packet(SH31Type.LoadUnkown)) { packet.WriteInt(0xbd1); //lolwut?! charid or sumtin' client.SendPacket(packet); } }
public static void SendZoneServerIP(WorldClient client, ZoneConnection info) { using (var packet = new Packet(SH4Type.ServerIP)) { packet.WriteString(client.Host == "127.0.0.1" ? "127.0.0.1" : info.IP, 16); packet.WriteUShort(info.Port); client.SendPacket(packet); } }
public static void SendGuildNameResult(WorldClient client, int pID, string pName) { using (var packet = new Packet(SH29Type.GuildNameResult)) { packet.WriteInt(pID); packet.WriteString(pName, 16); client.SendPacket(packet); } }
public static void UnknownRequest(WorldClient client, Packet packet) { if (client.Character == null) { Log.WriteLine(LogLevel.Warn, "Getting unknown block request from unauthorized host: {0}.", client.Host); return; } SendUnknown(client); }
public static void SendServerTime(WorldClient client) { using (var packet = new Packet(SH2Type.ServerTime)) { packet.WriteByte(Convert.ToByte(DateTime.Now.Hour)); packet.WriteUShort(Convert.ToUInt16(DateTime.Now.Minute)); client.SendPacket(packet); } }
public static void SaveClientSettingsRequest(WorldClient client, Packet packet) { byte[] data; if (!packet.TryReadBytes(392, out data)) { Log.WriteLine(LogLevel.Warn, "Unable to read 392 bytes from stream for save"); return; } // Save it. client.Character.SetClientSettingsData(data); }
public static void SaveQuickBarStateRequest(WorldClient client, Packet packet) { byte[] data; if (!packet.TryReadBytes(24, out data)) { Log.WriteLine(LogLevel.Warn, "Unable to read 24 bytes from stream for save"); return; } // Save it. client.Character.SetQuickBarStateData(data); }
public static void CreateCharHandler(WorldClient client, Packet packet) { string name; byte slot, jobGender, hair, color, style; if (!packet.TryReadByte(out slot) || !packet.TryReadString(out name, 20) || !packet.TryReadByte(out jobGender) || !packet.TryReadByte(out hair) || !packet.TryReadByte(out color) || !packet.TryReadByte(out style)) { Log.WriteLine(LogLevel.Warn, "Error reading create char for {0}", client.Username); return; } if (DatabaseChecks.IsCharNameUsed(name)) { SendCharCreationError(client, CreateCharError.NameTaken); return; } else if (DataProvider.Instance.IsBadName(name)) { SendCharCreationError(client, CreateCharError.NameInUse); return; } byte isMaleByte = (byte)((jobGender >> 7) & 0x01); byte classIDByte = (byte)((jobGender >> 2) & 0x1F); Job job = (Job)classIDByte; switch (job) { case Job.Archer: case Job.Cleric: case Job.Fighter: case Job.Mage: case Job.Trickster: //create character here try { WorldCharacter wchar = client.CreateCharacter(name, slot, hair, color, style, job, Convert.ToBoolean(isMaleByte)); SendCharOKResponse(client, wchar); } catch (Exception ex) { Log.WriteLine(LogLevel.Exception, "Error creating character for {0}: {1}", client.Username, ex.InnerException.ToString()); SendCharCreationError(client, CreateCharError.FailedToCreate); return; } break; default: SendCharCreationError(client, CreateCharError.WrongClass); Log.WriteLine(LogLevel.Warn, "Invalid job ID at char creation from {0}", client.Username); break; } }
public static void SaveGameSettingsRequest(WorldClient client, Packet packet) { // Load up 64 B of data (well, try to) byte[] data; if (!packet.TryReadBytes(64, out data)) { Log.WriteLine(LogLevel.Warn, "Unable to read 64 bytes from stream for save"); return; } // Save it. client.Character.SetGameSettingsData(data); }
public static void SaveQuickBarRequest(WorldClient client, Packet packet) { // Load up 1 KB of data (well, try to) byte[] data; if (!packet.TryReadBytes(1024, out data)) { Log.WriteLine(LogLevel.Warn, "Unable to read 1024 bytes from stream for save"); return; } // Save it. client.Character.SetQuickBarData(data); }
public static void GuildNameRequest(WorldClient client, Packet packet) { int id; if (!packet.TryReadInt(out id)) { Log.WriteLine(LogLevel.Warn, "Failed reading Guild Name Request packet {0}", client.GetCharacterName()); return; } var guild = WorldGuild.GetGuild(id); if (guild == null) { SendGuildNameResult(client, id, ""); } else { SendGuildNameResult(client, id, guild.Name); } }
public static void DeleteCharacterHandler(WorldClient client, Packet packet) { byte slot; if (!packet.TryReadByte(out slot) || slot > 10 || !client.Characters.ContainsKey(slot)) { Log.WriteLine(LogLevel.Warn, "{0} tried to delete character out of range.", client.Username); return; } WorldCharacter todelete = client.Characters[slot]; if (todelete.Delete()) { client.Characters.Remove(slot); SendCharDeleteOKResponse(client, slot); } else { Handler3.SendError(client, ServerError.DATABASE_ERROR); } }
public static void TransferKey(WorldClient client, Packet packet) { string key; if (!packet.ReadSkip(256) || !packet.TryReadString(out key, 64)) { Log.WriteLine(LogLevel.Warn, "Invalid connection request."); client.Disconnect(); return; } ClientTransfer transfer = ClientManager.Instance.GetTransfer(key); if (transfer != null) { // Check if client does not connect from localhost or LAN, // and if it's connecting from the correct IP. // When this check is not done, people can remote hack someone. if (!client.Host.StartsWith("127.0") && !client.Host.StartsWith("192.") && transfer.HostIP != client.Host) { Log.WriteLine(LogLevel.Warn, "Remotehack from {0}", client.Host); SendError(client, ServerError.INVALID_CREDENTIALS); } else { if (ClientManager.Instance.RemoveTransfer(transfer.Hash) && (!Program.Maintenance || transfer.Admin > 0)) //admins can still login { client.Authenticated = true; client.AccountID = transfer.AccountID; client.Admin = transfer.Admin; client.Username = transfer.Username; client.lastPing = DateTime.Now; //this is so pongthread can start checking him client.Pong = true; client.RandomID = MathUtils.RandomizeUShort(ushort.MaxValue); Log.WriteLine(LogLevel.Debug, "{0} authenticated.", client.Username); SendCharacterList(client); } } } else { Log.WriteLine(LogLevel.Warn, "Invalid client authentication from {0}", client.Host); SendError(client, ServerError.INVALID_CREDENTIALS); } }
public static void BackToCharSelect(WorldClient pClient, Packet pPacket) { bool go; // dunno if (!pPacket.TryReadBool(out go)) { Log.WriteLine(LogLevel.Warn, "Couldn't read back to char select packet"); return; } if (!pClient.Authenticated) { Log.WriteLine(LogLevel.Warn, "Player tried using the back to char select packet while not able to"); return; } if (go) { SendCharacterList(pClient); } }
private static void SendCharDeleteOKResponse(WorldClient client, byte slot) { using (var packet = new Packet(SH5Type.CharDeleteOK)) { packet.WriteByte(slot); client.SendPacket(packet); } }
private static void SendCharCreationError(WorldClient client, CreateCharError error) { using (Packet packet = new Packet(SH5Type.CharCreationError)) { packet.WriteUShort((ushort)error); client.SendPacket(packet); } }
private static void SendCharOKResponse(WorldClient client, WorldCharacter character) { using (var packet = new Packet(SH5Type.CharCreationOK)) { packet.WriteByte(1); PacketHelper.WriteBasicCharInfo(character, packet); client.SendPacket(packet); } }
private static void SendCharacterList(WorldClient client) { if (!client.LoadCharacters()) { SendError(client, ServerError.DATABASE_ERROR); return; } using (var packet = new Packet(SH3Type.CharacterList)) { packet.WriteUShort(client.RandomID); packet.WriteByte((byte)client.Characters.Count); foreach (WorldCharacter ch in client.Characters.Values) { PacketHelper.WriteBasicCharInfo(ch, packet); } client.SendPacket(packet); } }
public static void ShortcutsRequest(WorldClient client, Packet packet) { SendShortcuts(client); }
public static void ServerTimeReq(WorldClient client, Packet packet) { SendServerTime(client); }
public static void GameSettingsRequest(WorldClient client, Packet packet) { SendGameSettings(client); }
public static void Pong(WorldClient client, Packet packet) { client.Pong = true; }
public override void OnClientConnect(Socket socket) { WorldClient client = new WorldClient(socket); ClientManager.Instance.AddClient(client); Log.WriteLine(LogLevel.Debug, "Client connected from {0}", client.Host); }
public static void QuickBarStateRequest(WorldClient client, Packet packet) { SendQuickbarState(client); }