public World Next(ServerUtilities.ServerType serverType) { foreach (World world in this) { if (serverType == ServerUtilities.ServerType.Char && world.IsFull) { continue; } else if (serverType == ServerUtilities.ServerType.Game && world.IsFull) { continue; } else if (serverType == ServerUtilities.ServerType.Message && world.IsFull) { continue; } else if (serverType == ServerUtilities.ServerType.Shop && world.ShopServer != null) { continue; } return(world); } return(null); }
private void OnRegistrationRequest(InPacket inPacket) { ServerUtilities.ServerType type = (ServerUtilities.ServerType)inPacket.ReadByte(); string securityCode = inPacket.ReadString(); IPEndPoint endPoint = new IPEndPoint(inPacket.ReadIPAddress(), inPacket.ReadUShort()); World world = LoginServer.Worlds.Next(type); bool worked = false; using (OutPacket outPacket = new OutPacket(InteroperabilityMessage.RegistrationResponse)) { if (securityCode != LoginServer.SecurityCode) { outPacket.WriteByte((byte)ServerUtilities.ServerRegistrationResponse.InvalidCode); Log.Error(ServerUtilities.RegistrationResponseResolver.Explain(ServerUtilities .ServerRegistrationResponse.InvalidCode)); } else if (world == null) { outPacket.WriteByte((byte)ServerUtilities.ServerRegistrationResponse.WorldsFull); Log.Error(ServerUtilities.RegistrationResponseResolver.Explain(ServerUtilities .ServerRegistrationResponse.WorldsFull)); } else { if (world.HostIP.ToString() != endPoint.Address.ToString()) { outPacket.WriteByte((byte)ServerUtilities.ServerRegistrationResponse.InvalidIP); Log.Error(ServerUtilities.RegistrationResponseResolver.Explain(ServerUtilities .ServerRegistrationResponse.InvalidIP)); } else { this._type = type; this.RemoteEndPoint = endPoint; this.WorldID = world.ID; switch (this._type) { case ServerUtilities.ServerType.Char: { this.World.CharServer = this; outPacket.WriteByte((byte)ServerUtilities.ServerRegistrationResponse.Valid); outPacket.WriteByte(this.WorldID); worked = true; } break; case ServerUtilities.ServerType.Game: { this.World.Add(this); this._id = (byte)this.World.Count; outPacket.WriteByte((byte)ServerUtilities.ServerRegistrationResponse.Valid); outPacket.WriteByte(this.WorldID); outPacket.WriteByte(this.ExternalID); outPacket.WriteString(this.World.ScrollingHeader); outPacket.WriteInt(this.World.Rates.Experience); outPacket.WriteInt(this.World.Rates.QuestExperience); outPacket.WriteInt(this.World.Rates.PartyQuestExperience); outPacket.WriteInt(this.World.Rates.Meso); outPacket.WriteInt(this.World.Rates.Loot); worked = true; } break; case ServerUtilities.ServerType.Message: { this.World.MessageServer = this; outPacket.WriteByte((byte)ServerUtilities.ServerRegistrationResponse.Valid); outPacket.WriteByte(this.WorldID); worked = true; } break; case ServerUtilities.ServerType.Shop: { this.World.ShopServer = this; outPacket.WriteByte((byte)ServerUtilities.ServerRegistrationResponse.Valid); outPacket.WriteByte(this.WorldID); worked = true; } break; } } } this.Send(outPacket); } if (worked) { switch (this._type) { case ServerUtilities.ServerType.Char: { Log.Success("Registered Char {0} at {1}.", this.World.Name, this.RemoteEndPoint); } break; case ServerUtilities.ServerType.Game: { Log.Success("Registered Game {0}-{1} at {2}.", this.World.Name, this.ExternalID, this.RemoteEndPoint); } break; case ServerUtilities.ServerType.Message: { Log.Success("Registered Message {0} at {1}.", this.World.Name, this.RemoteEndPoint); } break; case ServerUtilities.ServerType.Shop: { Log.Success("Registered Shop {0} at {1}.", this.World.Name, this.RemoteEndPoint); } break; } } else { Log.Warn("Server registration failed."); this.Stop(); } }