internal void RegisterClient(Packet pa) { HandshakePacket p = pa as HandshakePacket; if (p.Type == HandshakePacket.SessionType.ServerList) { Packet.Send(new DisconnectPacket(), ph.Stream); HandleDisconnect(null); ph.Stop(); return; } else if (p.Type == HandshakePacket.SessionType.Admin) { if (!Server.Administrators.Contains(p.Username)) { Packet.Send(new MetadataPacket { SData = new string[] { "admin_login", "false" } }, ph.Stream); Packet.Send(new DisconnectPacket(), ph.Stream); ph.Stop(); return; } Packet.Send(new MetadataPacket { SData = new string[] { "admin_login", "true" } }, ph.Stream); Admin = true; } ClientID = p.Username; if (MinecraftModUpdater.Version != p.Version) { Packet.Send(new MetadataPacket { SData = new string[] { "require_version", MinecraftModUpdater.Version } }, ph.Stream); Thread.Sleep(1000); ph.Stop(); return; } MinecraftModUpdater.Logger.Log(Logger.Level.Info, "Client {0} connected. ({1})", ClientID, IPAddress.Address); Packet.Send(new EncryptionStatusPacket { Encrypt = true, EncryptionIV = ph.Stream.IV, EncryptionKey = ph.Stream.Key }, ph.Stream); ph.Stream.Encrypted = true; Packet.Send(new MetadataPacket { SData = new string[] { "server_name", Config.ServerName }, FData = new float[] { 24.0f } }, ph.Stream); if (!Admin) { for (int i = 0; i < Server.Mods.Count; i++) { if (Server.Mods[i].WhitelistedUsers.Contains(ClientID) || !Server.Mods[i].BlacklistedUsers.Contains(ClientID)) { allowedMods.Add(Server.Mods[i]); } else { MinecraftModUpdater.Logger.Log(Logger.Level.Info, "NOT SENDING: " + Server.Mods[i].ModName); } } Packet.Send(new MetadataPacket { SData = new string[] { "splash_display", "Downloading Assets..." } }, ph.Stream); if (Server.BackgroundImage != null) { byte[] b = Extras.BytesFromImage(Server.BackgroundImage); Packet.Send(new ImagePacket { Type = ImagePacket.ImageType.Background, ShowOn = "", Image = b }, ph.Stream); } foreach (var v in Server.ModImages) { byte[] b = Extras.BytesFromImage(v.Value); Packet.Send(new ImagePacket { Type = ImagePacket.ImageType.Mod, ShowOn = v.Key.ModFile, Image = b }, ph.Stream); } } else { allowedMods.AddRange(Server.Mods.ToArray()); } string[] mods = new string[allowedMods.Count]; for (int i = 0; i < allowedMods.Count; i++) { mods[i] = allowedMods[i].Identifier; } Packet.Send(new MetadataPacket { SData = new string[] { "splash_display", "Downloading Mod List..." } }, ph.Stream); Packet.Send(new ModListPacket { Mods = mods }, ph.Stream); MinecraftModUpdater.Logger.Log(Logger.Level.Info, "{0} Logged in.", this.ClientID); if (Admin) { PacketHandler.RegisterPacketHandler(PacketId.AdminFileInfo, UpdateModInfo); PacketHandler.RegisterPacketHandler(PacketId.UploadFile, HandleFileUpload); PacketHandler.RegisterPacketHandler(PacketId.FilePart, HandleFilePart); PacketHandler.RegisterPacketHandler(PacketId.AllDone, HandleCompleteDownload); } else { if (Config.ClientVersion != "") { Packet.Send(new MetadataPacket { SData = new string[] { "version_downgrade", Config.ClientVersion } }, PacketHandler.Stream); } } }