/* Banana-Chat - The first Open Source Knuddels Emulator
 * Copyright (C) 2011 - 2012 Flav <http://banana-coding.com>
 * 
 * Diese Dateien unterliegen dem Coprytight von Banana-Coding und
 * darf verändert, aber weder in andere Projekte eingefügt noch
 * reproduziert werden.
 * 
 * Der Emulator dient - sofern der Client nicht aus Eigenproduktion
 * stammt - nur zu Lernzwecken, das Hosten des originalen Knuddels Clients
 * ist auf eigene Gefahr und verstößt möglicherweise gegen Schutzrechte
 * der Knuddels.de GmbH & Co KG
 * 
 * Autoren: Flav (Grundversion), Localhost (Erweiterte Version), Kokos-Ice (Erweiterte Version)
 */



package tools;

import java.util.Collection;
import java.util.List;
import java.util.Random;

import netchat.Channel;
import netchat.ChannelStyle;
import netchat.Client;
import netchat.ReceiveOpcode;
import netchat.SendOpcode;
import netchat.Server;

import tools.popup.Button;
import tools.popup.Choice;
import tools.popup.Label;
import tools.popup.Panel;
import tools.popup.Popup;
import tools.popup.TextArea;
import tools.popup.TextField;

public class PacketCreator {
	
	public static String createAdminCallWindow() {
		return "k\0Notruf - Grund Auswählenõscdiaõ805õf\0\0\0h¾¼ûd Abbrechen õãWl  õgMh¾¼ûãEl  õgMh¾¼ûãNlõgFh¾¼ûãSlõgFh¾¼ûãCpBNpBClNotruf - Grund AuswählenõlgSf\0\0\0hååÿãSlõgFh¾¼ûããCcBitte beachte, dass du einen Notruf nur in Notfällen einsetzen sollten. Bitte wähle den Grund des Notrufs aus.õs\0Kf\0\0\0h¾¼ûãSpBNpBNlNotruf-GrundõbgQf\0\0\0h¾¼ûãCogOã- Auswählen -õAllgemeine Frage / ProblemõBeschwerde über andere Chat-TeilnehmerõãSlõgPh¾¼ûããClõgFh¾¼ûãSpFb    OK    õsdbgQf\0\0\0h¾¼ûãb  ?  õsbgQf\0\0\0h¾¼ûãb Abbrechen õsdbgQf\0\0\0h¾¼ûããããã";
	}
	
	public static String createTeamInfoPopup(String team, String text) {
        Popup popup = new Popup(String.format("Teaminfo %s bearbeiten", team), String.format("Teaminfo %s bearbeiten", team), "", 0, 0);
        Panel panel7 = new Panel();
        TextArea a = new TextArea(15, 50);
        a.setText(text);
        panel7.addComponent(a);
        popup.addPanel(panel7);
        Panel panel2 = new Panel();
        Button button = new Button("Speichern");
        button.setStyled(true);
        button.enableAction();
        button.disableClose();
        panel2.addComponent(button);
        Button button2 = new Button("Abbrechen");
        button2.setStyled(true);
        panel2.addComponent(button2);
        popup.addPanel(panel2);
        popup.setOpcode(ReceiveOpcode.FA.getValue(), team);
        return popup.toString();
	}
	
	public static String createServerPopup(boolean edit, String module, String[] infos) {
		String text = String.format("Server - %s - %s", module, edit ? "Eintrag bearbeiten":"Neuer Eintrag");
        Popup popup = new Popup(text, text, "", 350, 0);
        popup.setButtonFontSize(17);
        Panel panel1 = new Panel();
        
        if(module.equalsIgnoreCase("wordmix")) {
        	panel1.addComponent(new Label("Satz:"));
        	panel1.addComponent(new TextField(30, infos[0]));
            popup.addPanel(panel1);
        } if(module.equalsIgnoreCase("werbung")) {
        	panel1.addComponent(new Label("Werbetext:"));
        	panel1.addComponent(new TextField(30, infos[0]));
            popup.addPanel(panel1);
        } else if(module.equalsIgnoreCase("todo")) {
        	panel1.addComponent(new Label("Text:"));
        	panel1.addComponent(new TextField(30, infos[0]));
            popup.addPanel(panel1);
        } else if(module.equalsIgnoreCase("teams")) {
        	panel1.addComponent(new Label("Team:"));
        	panel1.addComponent(new TextField(30, infos[0]));
            popup.addPanel(panel1);
        } else if(module.equalsIgnoreCase("rechte")) {
        	panel1.addComponent(new Label("Recht:"));
        	panel1.addComponent(new TextField(30, infos[0]));
            popup.addPanel(panel1);

            Panel panel3 = new Panel();
        	panel3.addComponent(new Label("Bezeichnungen:"));
        	panel3.addComponent(new TextField(30, infos[1]));
            popup.addPanel(panel3);
        } else if(module.equalsIgnoreCase("umfragen")) {
        	popup.setMessage("Hinweis: Antworten getrennt mit einem Semikolon schreiben.");
        	panel1.addComponent(new Label("Frage:"));
        	panel1.addComponent(new TextField(30, infos[0]));
            popup.addPanel(panel1);

            Panel panel3 = new Panel();
        	panel3.addComponent(new Label("Antworten:"));
        	panel3.addComponent(new TextField(30, infos[1]));
            popup.addPanel(panel3);
        } else if(module.equalsIgnoreCase("butler")) {
        	popup.setMessage("Replacements: {FROM__NICK}, {YEAR}, {DAY}, {MONTH}, {SECONDS}, {MINUTES}, {HOURS}, {MILISECONDS}, {WEEKDAY}");
        	popup.setHeight(100);
        	panel1.addComponent(new Label("Wort:"));
        	panel1.addComponent(new TextField(30, infos[0]));
            popup.addPanel(panel1);

            Panel panel3 = new Panel();
        	panel3.addComponent(new Label("Antworten:"));
        	panel3.addComponent(new TextArea(15,30,  infos[1]));
            popup.addPanel(panel3);
        } else if(module.equalsIgnoreCase("makros")) {
        	popup.setMessage("Replacements: [TEXT]");
        	popup.setHeight(100);
        	panel1.addComponent(new Label("Makro:"));
        	panel1.addComponent(new TextField(30, infos[0]));
            popup.addPanel(panel1);

            Panel panel3 = new Panel();
        	panel3.addComponent(new Label("Texte:"));
        	panel3.addComponent(new TextArea(15,30,  infos[1]));
            popup.addPanel(panel3);
        } else if(module.equalsIgnoreCase("wahlen")) {
        	panel1.addComponent(new Label("Name:"));
        	panel1.addComponent(new TextField(30, infos[0]));
            popup.addPanel(panel1);

            Panel panel4 = new Panel();
        	panel4.addComponent(new Label("Status:"));
        	String status = infos[1];
        	panel4.addComponent(new Choice(new String[] {"Aktiviert", "Deaktiviert"}, status.isEmpty() || Integer.parseInt(status) == 1 ? "Aktiviert":"Deaktiviert"));
            popup.addPanel(panel4);

            Panel panel5 = new Panel();
        	panel5.addComponent(new Label("Nominierungsphase:"));
        	panel5.addComponent(new TextField(30, infos[2]));
            popup.addPanel(panel5);

            Panel panel6 = new Panel();
        	panel6.addComponent(new Label("Wahlphase:"));
        	panel6.addComponent(new TextField(30, infos[3]));
            popup.addPanel(panel6);

            Panel panel7 = new Panel();
        	panel7.addComponent(new Label("Endphase:"));
        	panel7.addComponent(new TextField(30, infos[4]));
            popup.addPanel(panel7);
        } else if(module.equalsIgnoreCase("badwords")) {
        	panel1.addComponent(new Label("BadWord:"));
        	panel1.addComponent(new TextField(30, infos[0]));
            popup.addPanel(panel1);

            Panel panel4 = new Panel();
        	panel4.addComponent(new Label("Jugendschutz?"));
        	String jugendschutz = infos[1].trim();
        	panel4.addComponent(new Choice(new String[] {"Ja", "Nein"}, jugendschutz.isEmpty() || Integer.parseInt(jugendschutz) == 0 ? "Nein":"Ja"));
            popup.addPanel(panel4);
        } else if(module.equalsIgnoreCase("funktionen")) {
        	panel1.addComponent(new Label("Funktion:"));
        	panel1.addComponent(new TextField(30, infos[0]));
            popup.addPanel(panel1);

            Panel panel4 = new Panel();
        	panel4.addComponent(new Label("Beschreibung:"));
        	panel4.addComponent(new TextArea(15,30,  infos[1]));
            popup.addPanel(panel4);
            
            Panel panel5 = new Panel();
        	panel5.addComponent(new Label("Rang:"));
        	panel5.addComponent(new Choice(new String[] {"Newbie", "Familymitglied", "Stammi", "Ehrenmitglied", "Status 4", "inoffizieller Admin", "Admin Status 6", "Admin Status 7", "Sysadmin Status 8", "Sysadmin Status 9", "Sysadmin Status 10", "Sysadmin Status 11"}));
            popup.addPanel(panel5);
        } else if(module.equalsIgnoreCase("hilfe")) {
        	panel1.addComponent(new Label("Wort:"));
        	panel1.addComponent(new TextField(30, infos[0]));
            popup.addPanel(panel1);

            Panel panel4 = new Panel();
        	panel4.addComponent(new Label("Titel:"));
        	panel4.addComponent(new TextField(30, infos[1]));
            popup.addPanel(panel4);

            Panel panel5 = new Panel();
        	panel5.addComponent(new Label("Text:"));
        	panel5.addComponent(new TextArea(15,30,  infos[2]));
            popup.addPanel(panel5);
        } else if(module.equalsIgnoreCase("toplisten")) {
        	panel1.addComponent(new Label("Name:"));
        	panel1.addComponent(new TextField(30, infos[0]));
        	popup.addPanel(panel1);
        	
        	Panel panel4 = new Panel();
        	panel4.addComponent(new Label("Beschreibung:"));
        	panel4.addComponent(new TextArea(15,30,  infos[1]));
        	popup.addPanel(panel4);

        	Panel panel5 = new Panel();
        	panel5.addComponent(new Label("Datenbankfeld:"));
        	panel5.addComponent(new TextField(30, infos[2]));
        	popup.addPanel(panel5);
        }
        
        Panel panel2 = new Panel();
        Button button = new Button("Absenden");
        button.enableAction();
        button.setStyled(true);
        panel2.addComponent(button);
        Button button2 = new Button("Abbrechen");
        button2.setStyled(true);
        panel2.addComponent(button2);
        popup.addPanel(panel2);
                
        String end = String.format("%s%s", edit ? String.format("edit%s~~~", module.equalsIgnoreCase("makros")?infos[0]:infos[0]):"", module);
        popup.setOpcode(ReceiveOpcode.SERVER.getValue(), end);
        return popup.toString();
	}
	
	public static String createVerifyWindow(String nick, String email, int id) {
		StringBuilder builder = new StringBuilder();
		
		builder.append("k\0E-Mail-Verifizierung ");
		builder.append(nick);
		builder.append("õsmaillinksõframe|-739543851145446095|"+nick+"õf\0\0\0h¾¼ûãNl õgFh¾¼ûãEl         õgFh¾¼ûãWl         õgFh¾¼ûãSl õgFh¾¼ûãCpBNpBNlE-Mail-Verifizierung ");
		builder.append(nick);
		builder.append("õblgSf\0\0\0hååÿããCpBNpBNl õgMf\0\0\0h¾¼ûãCpGBCIFpBCc°12°Die E-Mail-Verifizierung ist sehr wichtig, um deinen Nicknamen vor Missbrauch durch Dritte zu schützen.##");
		
		if(id == 1) {
			builder.append("_°16°E-Mail-Adresse verifizieren°12°_##_°>number_1.b.my_10.h_14.gif<%15°Trage im Eingabefeld unten die gewünschte E-Mail-Adresse ein°%00°##°>number_2.b.my_10.h_14.gif<%15°Klicke auf \"\"Verifizieren\"\"°%00°_##°>number_3.b.my_10.h_14.gif<%15°Nach einer Bestätigung per /m erhältst du eine E-Mail°%00°##°>number_4.b.my_10.h_14.gif<%15°Klicke in dieser E-Mail auf den Verifizierungslink##Fertig!");
		} else {
			builder.append("#Die eingetragene E-Mail-Adresse kann aus folgendem Grund nicht verifiziert werden: _°R°E-Mail-Adresse fehlerhaft_°r°##Bitte wähle eine andere E-Mail-Adresse!");
		}
		
		builder.append("õs\"f\0\0\0h¾¼ûãSpBCf");
		builder.append(email);
		builder.append("õUf\0\0\0hÿÿÿãEpBWl õgSh¾¼ûãb Verifizieren õcesdpbgMf\0\0\0h¾¼ûããããããããã");
		
		return builder.toString();	
	}
	
	public static String protocolConfirmed() {
		PacketWriter packet = new PacketWriter();
		packet.writeString(SendOpcode.MODULE.getValue());
		packet.write(0x00);
		packet.writeShort(Server.get().getModuleTree().getIndex("PROTOCOL_CONFIRMED"));
		return packet.toString();
	}

	public static String changeProtocol() {
		PacketWriter packet = new PacketWriter();
		packet.writeString(SendOpcode.MODULE.getValue());
		packet.write(0x00);
		packet.writeShort(Server.get().getModuleTree().getIndex("CHANGE_PROTOCOL"));
		packet.writeShort(Server.get().getModuleTree().getTree().length());
		packet.writeString(Server.get().getModuleTree().getTree());
		return packet.toString();
	}
	
	public static String createInviteWindow(String nick, String name, String thema) {
		return "k\0Separee mit "+nick+" eröffnenõsinvõ"+nick+"õf\0\0\0h¾¼ûãEl         õcgFh¾¼ûãWl         õcgFh¾¼ûãCpBNpBNl õgIh¾¼ûãClSeparee mit "+nick+" eröffnenõblgSf\0\0\0hååÿãSl õgQh¾¼ûããCpBCcDu möchtest _"+nick+"_ in ein _Separee_ einladen.##Du musst nun einen _Namen_ für das Separee wählen, ein _Design_, optional einen _Test_ und zu guter letzt, ob du einen anwesenden _Butler_ magst, oder lieber ganz allein mit "+nick+" sein willst.õs\0f\0\0\0h¾¼ûipics/cloudsblue.gifõ\0ãSpGACDDl õgUh¾¼ûãl õgUh¾¼ûãlSeparee Name: õgOh¾¼ûãf"+name+"õUf\0\0\0hÿÿÿãlSeparee Thema: õgOh¾¼ûãf"+thema+"õUf\0\0\0hÿÿÿãlDesign: õgOh¾¼ûãoãBlumentapeteõBlaue WolkenõKerzeõHansi und eine Handvoll HerzenõPferde auf grünõSterneõErdbeerenõKirschenõStifte Radierer und KnöpfeõãlTest: õgOh¾¼ûãoãKein TestõÄhnlichkeitstestõMenschenkenntnistestõãlButler?õgOh¾¼ûãxstãl õgUh¾¼ûãl õgUh¾¼ûãb  OK  õsdpgSf\0\0\0h¾¼ûãb  Abbrechen  õdpgSf\0\0\0h¾¼ûããããã";
	}
	
    public static String createCodeActivateWindow() {
        Popup popup = new Popup("Code aktivieren", "Code aktivieren", "Gib weiter unten die vier Buchstabenblöcke ein, die du in der /m findest. Durch einen anschließenden Klick auf _Aktivieren_ wird dein Code für deinen Nicknamen aktiviert.#Beachte: Nach Aktivierung kann der Code nicht mehr verschenkt werden.", 350, 120);
        popup.setButtonFontSize(17);
        Panel panel1 = new Panel();
        panel1.addComponent(new Label("Code:"));
        panel1.addComponent(new TextField(4, ""));
        panel1.addComponent(new Label("-"));
        panel1.addComponent(new TextField(4, ""));
        panel1.addComponent(new Label("-"));
        panel1.addComponent(new TextField(4, ""));
        panel1.addComponent(new Label("-"));
        panel1.addComponent(new TextField(4, ""));
        popup.addPanel(panel1);
        Panel panel2 = new Panel();
        Button button = new Button("Aktivieren");
        button.setStyled(true);
        button.enableAction();
        button.disableClose();
        panel2.addComponent(button);
        Button button2 = new Button("Abbrechen");
        button2.setStyled(true);
        panel2.addComponent(button2);
        popup.addPanel(panel2);
                
        popup.setOpcode(ReceiveOpcode.CODE.getValue(), "activate");
        return popup.toString();
    }
    
	public static String createRoseWindow(String nick, String text) {
        Popup popup = new Popup("Rose versenden", "Rose versenden", "", 0, 0);
        popup.setHeaderFontSize(18);
        Panel panel1 = new Panel();
        panel1.addComponent(new Label("Empfänger (Nick):"));
        panel1.addComponent(new TextField(41, nick));
        popup.addPanel(panel1);
        Panel panel2 = new Panel();
        panel2.addComponent(new Label("Text zur Rose:                                                                                      "));
        popup.addPanel(panel2);
        Panel panel3 = new Panel();
        panel3.addComponent(new TextArea(15,60, text));
        popup.addPanel(panel3);
        Panel panel4 = new Panel();
        Button button = new Button("Absenden");
        button.setStyled(true);
        button.enableAction();
        panel4.addComponent(button);
        Button button2 = new Button("Schließen");
        button.setStyled(true);
        panel4.addComponent(button);
        popup.addPanel(panel4);

        popup.setOpcode(ReceiveOpcode.ROSE.getValue(), "rose");
        return popup.toString();
	}
    
	public static String createCodeGiveAwayWindow(String nick, String text) {
        Popup popup = new Popup("Code verschenken", "Code verschenken", "", 0, 0);
        Panel panel0 = new Panel();
        panel0.addComponent(new Label("Empfänger (Nick):"));
        panel0.addComponent(new TextField(41, nick));
        popup.addPanel(panel0);
        Panel panel1 = new Panel();
        panel1.addComponent(new Label("Code:          "));
        panel1.addComponent(new TextField(4, ""));
        panel1.addComponent(new Label("-"));
        panel1.addComponent(new TextField(4, ""));
        panel1.addComponent(new Label("-"));
        panel1.addComponent(new TextField(4, ""));
        panel1.addComponent(new Label("-"));
        panel1.addComponent(new TextField(4, ""));
        popup.addPanel(panel1);
        Panel panel2 = new Panel();
        panel2.addComponent(new Label("Text zum Geschenk:                                                                            "));
        popup.addPanel(panel2);
        Panel panel3 = new Panel();
        panel3.addComponent(new TextArea(10,60, text));
        popup.addPanel(panel3);
        Panel panel4 = new Panel();
        Button button = new Button("Verschenken");
        button.setStyled(true);
        button.enableAction();
        panel4.addComponent(button);
        Button button2 = new Button("Schließen");
        button2.setStyled(true);
        panel4.addComponent(button2);
        popup.addPanel(panel4);

        popup.setOpcode(ReceiveOpcode.CODE.getValue(), "giveaway");
        return popup.toString();
	}
    
	public static String createHZEditorWindow(String channel, String text) {
		String title = String.format("HZ-Editor - Channel %s", channel);
        Popup popup = new Popup(title, title, "", 0, 0);
        Panel panel2 = new Panel();
        panel2.addComponent(new Label("Hauptzuständige Admins:                                        "));
        popup.addPanel(panel2);
        Panel panel3 = new Panel();
        panel3.addComponent(new TextArea(5,40, text));
        popup.addPanel(panel3);
        Panel panel4 = new Panel();
        Button button = new Button("Speichern");
        button.setStyled(true);
        button.enableAction();
        panel4.addComponent(button);
        Button button2 = new Button("Schließen");
        button2.setStyled(true);
        panel4.addComponent(button2);
        popup.addPanel(panel4);

        popup.setOpcode(ReceiveOpcode.EDITOR.getValue(), String.format("HZA~%s", channel));
        return popup.toString();
	}
    
	public static String createRightsEditorWindow(String permission, String rights) {
		String title = String.format("Rights-Editor - Recht %s", permission);
        Popup popup = new Popup(title, title, "", 0, 0);
        Panel panel2 = new Panel();
        panel2.addComponent(new Label("Bezeichnungen:                                                        "));
        popup.addPanel(panel2);
        Panel panel3 = new Panel();
        panel3.addComponent(new TextArea(5,40, rights));
        popup.addPanel(panel3);
        Panel panel4 = new Panel();
        Button button = new Button("Speichern");
        button.enableAction();
        button.setStyled(true);
        panel4.addComponent(button);
        Button button2 = new Button("?");
        button2.setStyled(true);
        button2.enableAction();
        button2.disableClose();
        panel4.addComponent(button2);
        Button button3 = new Button("Schließen");
        button3.setStyled(true);
        panel4.addComponent(button3);
        popup.addPanel(panel4);

        popup.setOpcode(ReceiveOpcode.EDITOR.getValue(), String.format("RIGHTS~%s", permission));
        return popup.toString();
	}
	
    public static String createSnpWindow(String von, String nick, String password) {
        Popup popup = new Popup("Neues Passwort setzen", "Neues Passwort setzen", "", 0, 0);
        Panel panel1 = new Panel();
        panel1.addComponent(new Label(String.format("Nick:                     ")));
        panel1.addComponent(new TextField(25, nick));
        popup.addPanel(panel1);
        Panel panel2 = new Panel();
        panel2.addComponent(new Label("Neues Passwort:"));
        panel2.addComponent(new TextField(25, password));
        popup.addPanel(panel2);
        Panel panel4 = new Panel();
        Button button = new Button("Ändern");
        button.setStyled(true);
        button.enableAction();
        panel4.addComponent(button);
        Button button2 = new Button("Abbrechen");
        button2.setStyled(true);
        panel4.addComponent(button2);
        popup.addPanel(panel4);

        popup.setOpcode(ReceiveOpcode.SNP.getValue(), von);
        return popup.toString();
    }
	
	public static String createCodeWindow() {
        Popup popup = new Popup("Code Menu", "Code Menu", "", 0, 0);
        popup.setButtonFontSize(15);
        popup.setHeaderFontSize(17);
        
        Panel panel1 = new Panel();
        Button buttonMessage = new Button("         Codes aktivieren         ");
        buttonMessage.setStyled(true);
        buttonMessage.setCommand("/code activate");
        buttonMessage.disableClose();
        panel1.addComponent(buttonMessage);
        popup.addPanel(panel1);
        Panel panel4 = new Panel();
        Button button = new Button("    Eigene Codes ansehen   ");
        button.setStyled(true);
        button.setCommand("/code ?");
        buttonMessage.setStyled(true);
        button.disableClose();
        panel4.addComponent(button);
        popup.addPanel(panel4);
        Panel panel8 = new Panel();
        Button button8 = new Button("    Letzte Tausch-Aktionen   ");
        buttonMessage.setStyled(true);
        button8.setCommand("/code swapactions");
        button8.setStyled(true);
        button8.disableClose();
        panel8.addComponent(button8);
        popup.addPanel(panel8);
        Panel panel6 = new Panel();
        Button button6 = new Button("         Codes tauschen         ");
        button6.setCommand("/code swap");
        button6.setStyled(true);
        button6.disableClose();
        panel6.addComponent(button6);
        popup.addPanel(panel6);
        Panel panel0 = new Panel();
        Button button0 = new Button("      Codes verschenken       ");
        button0.setStyled(true);
        button0.setCommand("/code giveaway");
        button0.disableClose();
        panel0.addComponent(button0);
        popup.addPanel(panel0);
        Panel panel5 = new Panel();
        Button butto = new Button("            Smiley-Shop            ");
        butto.setCommand("/shop");
        butto.setStyled(true);
        butto.disableClose();
        panel5.addComponent(butto);
        popup.addPanel(panel5);
        Panel panel2 = new Panel();
        panel2.addComponent(new Label(" "));
        popup.addPanel(panel2);
        Panel panel3 = new Panel();
        Button button11 = new Button("             Schließen               ");
        button11.setStyled(true);
        panel3.addComponent(button11);
        popup.addPanel(panel3);

        return popup.toString();
	}
	
	public static String createSignatureWindow(Client client) {
        StringBuilder builder = new StringBuilder();
        
        builder.append("k\0Einstellungen - Briefkastenõspostõmowõf47VhÜÜþãEl  õcgPhÜÜþãWl  õcgPhÜÜþãSl õcgPhÜÜþãNl õcgPhÜÜþãCpBNpBNpBNlEinstellungen deines BriefkastensõgMfÜÜþh47VãClõgBhÜÜþããWpGABCCxs");
        builder.append(client.getMessageSound() == 1 ? "t":"f");
        builder.append("lSound bei neuer Nachrichtõf47VhÜÜþgMããCpGABCClõgMf47VhÜÜþãlõgMf47VhÜÜþãlõgMf47VhÜÜþãããCpBNlSignatur unter deinen NachrichtenõgPf\0\0\0hÜÜþãCt");
        builder.append(client.getSignatur());
        builder.append("õIB~signatureõef47VhÿÿÿgOãSpBNl            õgPf47VhÜÜþãWb     Speichern     õcesdbãEb     Abbrechen     õcedbããããã");
       
        return builder.toString();
	}
	
	public static String createPollWindow(String channel) {
        Popup popup = new Popup("Umfrage erstellen", "Umfrage erstellen", "Gib unten eine Frage und mindestens zwei verschiedene Antwortmöglichkeiten - durch Semikolons getrennt - ein. Jeder Chatter hat dann die Möglichkeit die Umfrage innerhalb von einer Minute zu beantworten und dabei 25 Knuddels abzusahnen, welche unter allen Teilnehmern verlost werden.", 400, 200);

        Panel panel1 = new Panel();
        panel1.addComponent(new Label("Frage:"));
        panel1.addComponent(new TextField(15, ""));
        panel1.addComponent(new Label("Antworten:"));
        panel1.addComponent(new TextField(15, ""));
        popup.addPanel(panel1);

        Panel panel2 = new Panel();
        Button button = new Button("Erstellen");
        button.setStyled(true);
        button.enableAction();
        panel2.addComponent(button);
        popup.addPanel(panel2);
        
        popup.setOpcode(ReceiveOpcode.POLL.getValue(), String.format("new~%s", channel));
        return popup.toString();
	}
	
	public static String createAdmincallWindow (String beschuldigter, String verstoß, String begründung) {
		String title = "Beschwerde über andere Chat-Teilnehmer";
        Popup popup = new Popup(title, title, "", 0, 0);
        
        Panel panel1 = new Panel();
        panel1.addComponent(new Label(String.format("Beschuldigter:")));
        panel1.addComponent(new TextField(30, beschuldigter));
        popup.addPanel(panel1);
        Panel panel2 = new Panel();
        String[] lala = {"- Auswählen -                                            ", "Spamming / Werbung / Knigge", "Botnutzung / Faken von Nachrichten", "Schwere Beleidigung / Bedrohung", "Foto-Verstoß", "Sexuelle Belästigung", "Verbotene Äußerung", "Profil-Verstoß", "HP-Verstoß", "Nickname unzulässig", "Spiel-Verstoß / Cheating", "Sonstiger Verstoß"};
        panel2.addComponent(new Label(String.format("Verstoß:          ")));
        panel2.addComponent(new Choice(lala, verstoß.trim()));
        popup.addPanel(panel2);
        Panel panel3 = new Panel();
        panel3.addComponent(new Label("Begründung:  "));
        panel3.addComponent(new TextArea(10,30, begründung));
        popup.addPanel(panel3);
        Panel panel5 = new Panel();
        Button button = new Button("Notruf absenden");
        button.enableAction();
        button.setStyled(true);
        panel5.addComponent(button);
        Button button2 = new Button("Abbrechen");
        button2.setStyled(true);
        panel5.addComponent(button2);
        popup.addPanel(panel5);
        
        Random random = new Random();
    	int randomInt = random.nextInt(9999999);

        popup.setOpcode(ReceiveOpcode.ADMINCALL.getValue(), String.valueOf(randomInt+1));
        return popup.toString();
	}
	public static String createMessageWindow(String an, String betreff, String text) {
		Popup popup = new Popup("Eine /m schreiben...", "Eine /m schreiben...", "", 0, 0);
		popup.setButtonFontSize(18);
        
        Panel panel1 = new Panel();
        panel1.addComponent(new Label(String.format("An (Nick):")));
        panel1.addComponent(new TextField(48, an));
        popup.addPanel(panel1);
        Panel panel2 = new Panel();
        panel2.addComponent(new Label("Betreff:     "));
        panel2.addComponent(new TextField(48, betreff));
        popup.addPanel(panel2);
        Panel panel3 = new Panel();
        panel3.addComponent(new Label("Nachricht:                                                                                            "));
        popup.addPanel(panel3);
        Panel panel4 = new Panel();
        panel4.addComponent(new TextArea(15,60, text));
        popup.addPanel(panel4);
        Panel panel5 = new Panel();
        Button button = new Button("Absenden");
        button.setStyled(true);
        button.enableAction();
        Button button2 = new Button("Vorschau");
        button2.setStyled(true);
        button2.enableAction();
        panel5.addComponent(button);
        panel5.addComponent(button2);
        Button button3 = new Button("Abbrechen");
        button3.setStyled(true);
        panel5.addComponent(button3);
        popup.addPanel(panel5);

        popup.setOpcode(ReceiveOpcode.MESSAGE.getValue(), "message");
        return popup.toString();
	}
	public static String createEmailWindow(String an, String text) {
		Popup popup = new Popup("E-Mail versenden", "E-Mail versenden", "", 0, 0);
		popup.setButtonFontSize(18);
        
        Panel panel1 = new Panel();
        panel1.addComponent(new Label(String.format("An (Nick):")));
        panel1.addComponent(new TextField(48, an));
        popup.addPanel(panel1);
        Panel panel3 = new Panel();
        panel3.addComponent(new Label("Nachricht:                                                                                            "));
        popup.addPanel(panel3);
        Panel panel4 = new Panel();
        panel4.addComponent(new TextArea(15,60, text));
        popup.addPanel(panel4);
        Panel panel5 = new Panel();
        Button button = new Button("Absenden");
        button.setStyled(true);
        button.enableAction();
        panel5.addComponent(button);
        Button button2 = new Button("Schließen");
        button2.setStyled(true);
        panel5.addComponent(button2);
        popup.addPanel(panel5);

        popup.setOpcode(ReceiveOpcode.EMAIL.getValue(), "email");
        return popup.toString();
	}
	
	public static String boldNames(List<String> names) {
        PacketBuilder buffer = new PacketBuilder(SendOpcode.BOLD_NAMES.getValue());

        for(String name : names) {
        	buffer.writeByte(0x00);
        	buffer.writeString(name.toLowerCase());
        }

        return buffer.toString();
    }

    public static String kontoPw(String name) {
		return "k\0Schweizer Knuddelskonto - Kontopasswort setzenõsknuddelsaõ"+name+"õf\0\0\0h¾¼ûãWl  õgMh¾¼ûãEl  õgMh¾¼ûãNlõgFh¾¼ûãSlõgFh¾¼ûãCpBNpBClKontopasswort setzenõblgSf\0\0\0hååÿãSlõgFh¾¼ûããCc°15°Bevor Du Knuddels auf Deinem Knuddelskonto in der Schweiz bunkern kannst, musst Du ein Kontopasswort festlegen.##_Beachte:_##  °>py_g.gif<%05°_Merke_ Dir Dein Kontopasswort gut!°%00°#  °>py_g.gif<%05°Das Kontopasswort _wird zum Codes/Smileys tauschen_ benötigt.°%00°#  °>py_g.gif<%05°Bei Vergessen/Verlust ist eine Neusetzung durch Admins oder das System etc. _nicht möglich_.õsô\0¾f\0\0\0h¾¼ûãSpBNpBWpGABCClKontopasswort:   õbgPf\0\0\0h¾¼ûãlKontopasswort wdh.:   õbgPf\0\0\0h¾¼ûããCpGABCCfõMf\0\0\0hÿÿÿc*ãfõMf\0\0\0hÿÿÿc*ãããCl õgMh¾¼ûãSpFbKontopasswort speichernõsdbgQf\0\0\0h¾¼ûãb  Abbrechen  õdbgQf\0\0\0h¾¼ûããããã";
	}
	
	public static String kontoPwNew(String name) {
		return "k\0Schweizer Knuddelskonto - Kontopasswort setzenõsknuddelsaõ"+name+"õf\0\0\0h¾¼ûãWl  õgMh¾¼ûãEl  õgMh¾¼ûãNlõgFh¾¼ûãSlõgFh¾¼ûãCpBNpBClKontopasswort setzenõblgSf\0\0\0hååÿãSlõgFh¾¼ûããCc°15°Gib unten zuerst Dein altes Kontopasswort an, um ein neues zu setzen.##_Beachte:_##  °>py_g.gif<%05°_Merke_ Dir Dein Kontopasswort gut!°%00°#  °>py_g.gif<%05°Das Kontopasswort _wird zum Codes/Smileys tauschen_ benötigt.°%00°#  °>py_g.gif<%05°Bei Vergessen/Verlust ist eine Neusetzung durch Admins oder das System etc. _nicht möglich_.õsô\0¾f\0\0\0h¾¼ûãSpBNpBWpGABCClAltes Kontopasswort:   õbgPf\0\0\0h¾¼ûãl õgFh¾¼ûãlNeues Kontopasswort:   õbgPf\0\0\0h¾¼ûãlNeues Kontopasswort wdh.:   õbgPf\0\0\0h¾¼ûããCpGABCCfõMf\0\0\0hÿÿÿc*ãl õgFh¾¼ûãfõMf\0\0\0hÿÿÿc*ãfõMf\0\0\0hÿÿÿc*ãããCl õgMh¾¼ûãSpFbKontopasswort setzenõsdbgQf\0\0\0h¾¼ûãb  Abbrechen  õdbgQf\0\0\0h¾¼ûããããã";
	}
	
	public static String konto(String name, int knuddels) {
		return "k\0Schweizer Knuddelskontoõsknuddelsaõ"+name+"õf\0\0\0h¾¼ûãWl  õgMh¾¼ûãEl  õgMh¾¼ûãNlõgFh¾¼ûãSlõgFh¾¼ûãCpBNpBClSchweizer KnuddelskontoõblgSf\0\0\0hååÿãSlõgIh¾¼ûããCc°15°  °>py_g.gif<%05°Aktuell maximal _verfügbarer Knuddels-Betrag:  "+knuddels+"_°%00°#  °>py_g.gif<%05°Neue Knuddels durch _Vermehrung zum 15.03.2012:  "+knuddels+"_ (10% pro Jahr)_°%00°##°-°õs:\0nf\0\0\0h¾¼ûãSpBWpBWpGABCClKnuddels:   õbgPf\0\0\0h¾¼ûãlAktion:   õbgPf\0\0\0h¾¼ûãlKontopasswort:   õbgPf\0\0\0h¾¼ûãl õgFh¾¼ûãl õgFh¾¼ûããCpGABCCfõMf\0\0\0hÿÿÿãogOãAktion wählen... õEinzahlenõAbhebenõãfõMf\0\0\0hÿÿÿc*ãl õgFh¾¼ûãpBWb  OK  õsdbgPf\0\0\0h¾¼ûãCl   õgIh¾¼ûãEb  Abbrechen  õdbgPf\0\0\0h¾¼ûããããCpGABCCl õgFh¾¼ûãl õgFh¾¼ûãpBWl  õgFh¾¼ûãClKontopasswort ändernõbgPf\0\0ÿh¾¼ûsKontopasswort ändernõuããl õgFh¾¼ûãl õgFh¾¼ûããããã";
	}
    
	public static String updateBillardFunctions(String channel) {
        PacketBuilder buffer = new PacketBuilder(SendOpcode.UPDATE_BILLARD_FUNCTIONS.getValue());
        
        buffer.writeByte(0x00);
        buffer.writeString(channel);
        buffer.writeByte(0x00);
        buffer.writeString("l");
        buffer.writeByte(0x00);
        buffer.writeString("/billard j:"); // join
        buffer.writeByte(0x00);
        buffer.writeString("L");
        buffer.writeByte(0x00);
        buffer.writeString("/billard j:"); // join
        buffer.writeByte(0x00);
        buffer.writeString("r");
        buffer.writeByte(0x00);
        buffer.writeString("/billard i:"); // info
        buffer.writeByte(0x00);
        buffer.writeString("R");
        buffer.writeByte(0x00);
        buffer.writeString("/billard i:"); // info
        buffer.writeByte(0x00);
        buffer.writeString("m");
        buffer.writeByte(0x00);
        buffer.writeString("/billard j:"); // join

        return buffer.toString();
    }

    public static String billardListAddNick(Channel channel, Client nick) {
        PacketBuilder buffer = new PacketBuilder(SendOpcode.BILLARD_LIST.getValue());
        
        buffer.writeByte(0x00);
        buffer.writeString("l");
        buffer.writeByte(0x00);
        buffer.writeString(channel.getName());
        buffer.writeByte(0x00);
        buffer.writeString(nick.getName());
        buffer.writeByte(0x00);
        buffer.writeString("p");
        buffer.writeByte(0x00);
        buffer.writeString(channel.getStyle().getRankColor(nick));
        buffer.writeByte(0x00);
        buffer.writeString("-");

        return buffer.toString();
    }

    public static String moduleClass(String channel, String module) {
        PacketBuilder buffer = new PacketBuilder(SendOpcode.MODULECLASS.getValue());
        
        buffer.writeByte(0x00);
        buffer.writeString("0");
        buffer.writeByte(0x00);
        buffer.writeString(channel);
        buffer.writeByte(0x00);
        buffer.writeString(module);

        return buffer.toString();
    }

    public static String billardListRemoveNick(String channel, String nick) {
        PacketBuilder buffer = new PacketBuilder(SendOpcode.BILLARD_LIST.getValue());
        
        buffer.writeByte(0x00);
        buffer.writeString("w");
        buffer.writeByte(0x00);
        buffer.writeString(nick);
        buffer.writeByte(0x00);
        buffer.writeString(channel);

        return buffer.toString();
    }
    
    public static String billardList(String channel, String text) {
        PacketBuilder buffer = new PacketBuilder(SendOpcode.BILLARD_LIST.getValue());
        
        buffer.writeByte(0x00);
        buffer.writeString("u");
        buffer.writeByte(0x00);
        buffer.writeString(channel);
        buffer.writeByte(0x00);
        buffer.writeString(text); // Der Text, der in dem Button steht
        buffer.writeByte(0x00);
        buffer.writeString("p");
        buffer.writeByte(0x00);
        buffer.writeString("-");
        buffer.writeByte(0x00);
        buffer.writeString("-");

        return buffer.toString();
    }
    
    public static String closeBillardList(String channel) {
        PacketBuilder buffer = new PacketBuilder(SendOpcode.CLOSE_BILLARD_LIST.getValue());
        
        buffer.writeByte(0x00);
        buffer.writeString(channel);

        return buffer.toString();
    }
	
	public static String votePopup(String election, List<String> params) {
        PacketBuilder buffer = new PacketBuilder(SendOpcode.VOTE.getValue());
        
        buffer.writeByte(0x00);
        buffer.writeString(election);
        buffer.writeByte(0x00);
        buffer.writeByte('5'); //positive Stimmen insgesamt
        buffer.writeByte(0x00);
        buffer.writeByte('3'); //negative Stimmen insgesamt
        buffer.writeByte(0x00);
        buffer.writeByte('2'); //maximale positive Stimmen pro Nick
        buffer.writeByte(0x00);
        buffer.writeByte('2'); //negative positive Stimmen pro Nick
        buffer.writeByte(0x00);
        buffer.writeString(String.valueOf(params.size())); //Wahlteilnehmer

        for (int i = 0; i < params.size(); i++) {
            String temp = params.get(i);
            String[] splitted = temp.split("~");
            String nick = splitted[0];
            String info = splitted[1];

            buffer.writeByte(0x00);
            buffer.writeByte(0x00);
            buffer.writeString(nick);
            buffer.writeByte(0x00);
            buffer.writeByte(0x00);
            buffer.writeString(info);
            buffer.writeByte(0x00);
            buffer.writeByte(0x00);
        }
        
        return buffer.toString();
    }
	
    public static String effect(String sender, String effect) {
        PacketBuilder buffer = new PacketBuilder(SendOpcode.EFFECT.getValue());
        buffer.writeByte(0x00);
        buffer.writeString("a");
        buffer.writeByte(0x00);
        buffer.writeString(sender);
        buffer.writeByte(0x00);
        buffer.writeString(effect);

        return buffer.toString();
    }

    public static String showPrefixIcons(String channelName, List<String> params) {
        PacketBuilder buffer = new PacketBuilder(SendOpcode.MODULE.getValue());

        buffer.writeByte(0);
        buffer.writeByte(0);
        buffer.writeByte(73);
        buffer.writeString(channelName, true, false); // Channelname
        buffer.writeByte(11);
 
        for (int i = 0; i < params.size(); i++) {
            String[] temp = params.get(i).split("~");
            String nick = temp[0];

            buffer.writeString(nick, true, false); // Nick
 
            for (int j = 1; j < temp.length; j++) {
                String icon = temp[j];
                buffer.writeByte(11);
                buffer.writeString(icon, true, false); // Icon
            }
 
            if (i < params.size() - 1) {
                buffer.writeByte(12);
                buffer.writeByte(11);
            }
        }
        
        buffer.writeByte(12);
        buffer.writeByte(12);
        buffer.writeByte(1);

        return buffer.toString();
    }

    public static String removePrefixIcons(String channelName) {
        PacketBuilder buffer = new PacketBuilder(SendOpcode.MODULE.getValue());

        buffer.writeByte(0);
        buffer.writeByte(0);
        buffer.writeByte(74); // "Opcode"
        buffer.writeString(channelName, true, false);

        return buffer.toString();
    }
    
    public static String removeEffect(String sender, String effect) {
        PacketBuilder buffer = new PacketBuilder(SendOpcode.EFFECT.getValue());
        buffer.writeByte(0x00);
        buffer.writeString("r");
        buffer.writeByte(0x00);
        buffer.writeString(sender);
        buffer.writeByte(0x00);
        buffer.writeString(effect);

        return buffer.toString();
    }
    
    public static String tauschFenster(boolean save, List<String> smileys) {
        StringBuilder builder = new StringBuilder();
        builder.append("k\0Codes tauschenõscodeõCodes tauschen~");
        builder.append(save ? 'T' : 'F');
        builder.append("õf\0\0\0");
        if (save) {
            builder.append("h¾¼ûãWl  õgMh¾¼ûãEl  õgMh¾¼ûãNlõgFh¾¼ûãSlõgFh¾¼ûãCpBCpBCpBCc");
            builder.append("°15°#Der Smileytausch ist durch den Smiley \"Plüsch-Devil-Krösus\" geschützt. Bitte gib dein Schweizer Knuddelskonto-Passwort ein.õsÌ\0Kf\0\0\0h¾¼ûi-õ\0\0oãSpGBAFFlKontopasswort: õbgPf\0\0\0h¾¼ûãfõUf\0\0\0hÿÿÿc*");
            builder.append("gOãlõgFh¾¼ûãããSlõgHh¾¼ûããNpBNpBCl");
        } else {
            builder.append("h¾¼ûãWl  õgMh¾¼ûãEl  õgMh¾¼ûãNlõgFh¾¼ûãSlõgFh¾¼ûãCpBCpBSlõgHh¾¼ûããNpBNpBCl");
        }

        builder.append("Codes tauschen");
        builder.append("õlgSf\0\0\0hååÿãSlõgFh¾¼ûããCpBNc#Gib den Nicknamen, mit dem du tauschen willst, ein. Klicke anschließend auf alle Häkchen von den Codes, die du tauschen möchtest.õs\0Pf\0\0\0h¾¼ûi-õ\0\0ãCpBWpBNlõgDh¾¼ûãWlTauschen mit (Nick): õgPh¾¼ûãCfõMf\0\0\0hÿÿÿãSlõgDh¾¼ûããClõgDh¾¼ûãEpBNlõgDh¾¼ûãClZusätzliche Knuddels: õgPh¾¼ûãEfõMf\0\0\0hÿÿÿãSlõgDh¾¼ûãããSc");
        
        builder.append("°30° °r°");
        int counter = -1;

        for (int i = 0; i < smileys.size(); i++) {
            counter++;

            builder.append("°%");

            switch (counter + 1) {
                case 1:
                    builder.append("0");
                    break;
                case 2:
                    builder.append("18");
                    break;
                case 3:
                    builder.append("37");
                    break;
                case 4:
                    builder.append("56");
                    break;
                case 5:
                    builder.append("75");
                    break;
            }

            builder.append("°");

            builder.append("°>{checkbox");
            builder.append(i + 1);
            builder.append("<>}checkbox<° ");
            
            if (!smileys.get(i).startsWith("°>")) {
                builder.append("°>");
                builder.append(smileys.get(i));
                builder.append("<°");
            } else {
                builder.append(smileys.get(i));
            }
            
            if (i == smileys.size() - 1) {
                builder.append("°%00°");
                break;
            }
            
            if ((i + 1) % 5 == 0) {
                builder.append("°%00°");
                builder.append("#°30° °r°");
                counter = -1;
                continue;
           }

       }

       builder.append("#õs \0×tsendbackõf\0\0\0h¾¼ûi-õ\0\0ãããSpFbTauschenõcesdbgQf\0\0\0h¾¼ûãbSchließenõcedgQf\0\0\0h¾¼ûãããã");
       return builder.toString();
   }

    public static String createEditWindow(Client client) {   
        StringBuilder channels = new StringBuilder();
            
        for (Channel name : Server.get().getChannels()) {
        	if(name.isVisible()) {
        		channels.append("õ").append(name.getName());          
        	}
        }
        
        char relationChar = 'A';
        
        if(client.getVergeben().equals("Single")) {
            relationChar = 'B';
        } else if(client.getVergeben().equals("Glücklicher Single")) {
            relationChar = 'C';
        } else if(client.getVergeben().equals("Verliebt")) {
            relationChar = 'D';
        } else if(client.getVergeben().equals("Unglücklich Verliebt")) {
            relationChar = 'E';
        } else if(client.getVergeben().equals("Vergeben")) {
            relationChar = 'F';
        } else if(client.getVergeben().equals("Glücklich Vergeben")) {
            relationChar = 'G';
        } else if(client.getVergeben().equals("Verlobt")) {
            relationChar = 'H';
        } else if(client.getVergeben().equals("Verheiratet")) {
            relationChar = 'I';
        } else if(client.getVergeben().equals("Glücklich Verheiratet")) {
            relationChar = 'J';
        } else if(client.getVergeben().equals("Geschieden")) {
            relationChar = 'K';
        } else if(client.getVergeben().equals("Glücklich Geschieden")) {
            relationChar = 'L';
        } else if(client.getVergeben().equals("Beziehungsgestört")) {
            relationChar = 'M';
        } else if(client.getVergeben().equals("Ich geh ins Kloster")) {
            relationChar = 'N';
        } else if(client.getVergeben().equals("offene Beziehung")) {
            relationChar = 'O';
        }
        
        char searchingGender = 'A';
        
        if(client.getSearchGender().equals("männl.")) {
            searchingGender = 'B';
        } else if(client.getSearchGender().equals("weibl.")) {
            searchingGender = 'C';
        }
        
        char searchingForBlinddate = 'A';
        
        if(client.getSearchMotiv().equals("Partnerschaft")) {
            searchingForBlinddate = 'B';
        } else if(client.getSearchMotiv().equals("Abenteuer")) {
            searchingForBlinddate = 'C';
        } else if(client.getSearchMotiv().equals("gutes Gespräcb")) {
            searchingForBlinddate = 'D';
        }
        
        char searchingForDistance = 'A';
        
        if(client.getSearchEntfernung().equals("20 km")) {
            searchingForDistance = 'B';
        } else if(client.getSearchEntfernung().equals("50 km")) {
            searchingForDistance = 'C';
        } else if(client.getSearchEntfernung().equals("150 km")) {
            searchingForDistance = 'D';
        } else if(client.getSearchEntfernung().equals("300 km")) {
            searchingForDistance = 'E';
        } else if(client.getSearchEntfernung().equals("egal")) {
            searchingForDistance = 'F';
        } 
        
        StringBuilder builder = new StringBuilder();

        builder.append("k\0Editõsgõ");
        builder.append(client.getName()); // Nickname
        builder.append('|');
        builder.append(client.getID()); // damit wird später gecheckt ob der Nick auch eingeloggt ist, Beispiel: 100101
        builder.append("õp\0ð\0\0fUhUãWl  õgMhUãEl  õgMhUãNlõgFhUãCpBWpBNpBNpBNpBNpBNl");
        builder.append("PflichtangabenõgMfUhÈÈúãClõgBhUããWpGABCClPasswortõgMfÈÈúhUsPasswortõãlNeues PasswortõgMfÈÈúhUsNeues PasswortõãlNeues Passwort (2x) õgMfÈÈúhUsNeues Passwort (2x) õãlEmailõgMfÈÈúhUsEmailõãlE-Mail verifiziert?õgMfÈÈúhUsE-Mail verifiziert?õããCpGABCCfõBhÿÿÿc*ãfõBhÿÿÿc*ãfõBhÿÿÿc*ãf");
        builder.append(client.getEmail()); // Email
        builder.append("õBhÿÿÿã");
        
        if(client.getEmailVerify() < 2) {
            builder.append("b");
            builder.append(client.getEmailVerify()==0?"E-Mail verifizieren":"Verifizierung läuft...");
            builder.append("õo");
        } else {
        	builder.append("l");
        	builder.append("Verifiziert!"); // Verifiziert? (Status)
        	builder.append("õc");
        }
        
        builder.append("gMfÈÈúhUããããCl õgIhUããCpBNpBNpBNlPrivatsphäreõgMfUhÈÈúãClõgBhUããCpGABCCxs");
        builder.append(client.getShowEmail() == 1 ? "t" : "f"); // Email anzeigen (t für checked, f für unchecked)
        builder.append("lE-Mail anzeigenõfÈÈúgMãxs");
        builder.append(client.getEmails() == 1 ? "t" : "f"); // Empfang von /email (t für checked, f für unchecked)
        builder.append("lEmpfang von /emailõfÈÈúgMãxs");
        builder.append(client.getShowBirthday() == 1 ? "t" : "f"); // Geburtsdatum anzeigen (s.o.)
        builder.append("lGeburtsdatum anzeigenõfÈÈúgMãxs");
        builder.append(client.getShowZodiac() == 1 ? "t" : "f"); // Sternzeichen anzeigen
        builder.append("lSternzeichen anzeigenõfÈÈúgMãxs");
        builder.append(client.getSearchActivate() == 1 ? "t" : "f"); // Suche aktiviert
        builder.append("lSuche aktiviertõfÈÈúgMãããCl õgIhUããSpBNpBNl");
        builder.append("Suche & Blinddate (Du suchst ...)õgMfUhÈÈúãClõgBhUãSpGBAAApBWlNicks werden mit õgMfÈÈúhUãCpBWcõs\0\0hUipics/1.gifõ\0oãCl angezeigt.õgMfÈÈúhUãããããWpGABCClGeschlechtõgMfÈÈúhUsGeschlechtõãlAlter      von: õgMfÈÈúhUsAlter      von: õãlMotivõgMfÈÈúhUsMotivõãlEntfernung bis õgMfÈÈúhUsEntfernung bis õããCpGABCCo");
        builder.append("c");
        builder.append(searchingGender); // A = 1. Eintrag (hier: nichts), B = 2. Eintrag (hier: männl.) ...
        builder.append("hÿÿÿã");
        builder.append(" õmännl.õweibl.õãpBWohÿÿÿã");
        builder.append(client.getSearchAgeFrom()==0?"":client.getSearchAgeFrom()); // Value (Alter von)
        builder.append("õ14õ15õ16õ17õ18õ19õ20õ21õ22õ23õ24õ25õ26õ28õ30õ32õ34õ36õ40õ45õ50õ55õ60õ70õ100");
        builder.append("õãCl     bis     õcgMfÈÈúhUãEohÿÿÿã");
        builder.append(client.getSearchAgeUntil()==0?"":client.getSearchAgeUntil()); // Value (Alter bis)
        builder.append("õ14õ15õ16õ17õ18õ19õ20õ21õ22õ23õ24õ25õ26õ28õ30õ32õ34õ36õ40õ45õ50õ55õ60õ70õ100");
        builder.append("õãão");
        builder.append("c");
        builder.append(searchingForBlinddate); // A = 1. Eintrag (empty), B = 2. Eintrag (Partnerschaft), C = 3. Eintrag (Abenteuer) etc.
        builder.append("hÿÿÿã õPartnerschaftõAbenteuerõgutes Gesprächõão");
        builder.append("c");
        builder.append(searchingForDistance); // Entfernung bis (A = 1. Eintrag, empty, C = 3. Eintrag, 50 km usw.)
        builder.append("hÿÿÿã õ20 kmõ50 kmõ150 kmõ300 kmõegalõããããCl  õgMhUãEpBNpBNpBNl");
        builder.append("Persönliches (freiwillig)õgMfUhÈÈúãClõgBhUããWpGABCClAlterõgMfÈÈúhUsAlterõãlDein GeschlechtõgMfÈÈúhUsDein GeschlechtõãlVergebenõgMfÈÈúhUsVergebenõãlStadtõgMfÈÈúhUsStadtõãlLandõgMfÈÈúhUsLandõãlHobbysõgMfÈÈúhUsHobbysõãlMottoõgMfÈÈúhUsMottoõãlRealnameõgMfÈÈúhUsRealnameõãlGeburtstagõgMfÈÈúhUsGeburtstagõãlLand / Postleitzahl (nie angezeigt) õgMfÈÈúhUsLand / Postleitzahl (nie angezeigt) õãlJobõgMfÈÈúhUsJobõãlSpitznamen (Komma getrennt)õgMfÈÈúhUsSpitznamen (Komma getrennt)õãl");
             
        if (client.getRank() > 1) {
            builder.append("LieblingschannelõgMfÈÈúhUsLieblingschannelõãl");
        }
             
        builder.append("Eigener ChannelõgMfÈÈúhUsEigener Channelõãl");
        builder.append("õgMfÈÈúhUããCpGABCCf");
        builder.append(client.getAge() > 0 ? client.getAge() : ""); // Alter Value
           
        if (client.getVerify() == 1) {
            builder.append("õBefhÀÀÀãoc");   
        } else {
            builder.append("õBhÿÿÿãoc");
        }
        
        char genderValueChar = 'A';
            
        if (client.getGender() == 1) {
            genderValueChar = 'B';
        } else if (client.getGender() == 2) {
            genderValueChar = 'C';
        } else {
            genderValueChar = 'A';
        }
            
        builder.append(genderValueChar); // Value Gender, A = empty, B = männl., C = weibl., ...
        builder.append("hÿÿÿã ");
        builder.append("õmännl.õweibl.õ");
        builder.append("ãoc");
        builder.append(relationChar); // A = empty, B = Single, ...
        builder.append("hÿÿÿã ");
        builder.append("õSingleõGlücklicher SingleõVerliebtõUnglücklich VerliebtõVergebenõGlücklich VergebenõVerlobtõVerheiratetõGlücklich VerheiratetõGeschiedenõGlücklich GeschiedenõBeziehungsgestörtõIch geh ins Klosterõoffene Beziehung"); // Auswahl Beziehungsstatus
        builder.append("õãf");
        builder.append(client.getStadt()); // Stadt
        builder.append("õBhÿÿÿãf");
        builder.append(client.getLand()); // Land
        builder.append("õBhÿÿÿãf");
        builder.append(client.getHobbys()); // Hobbies
        builder.append("õBhÿÿÿãf");
        builder.append(client.getMotto()); // Motto
        builder.append("õBhÿÿÿãf");
        builder.append(client.getRealName()); // Realname  
        builder.append("õBhÿÿÿãf");
        builder.append(client.getBirthday()); // Geburtsdatum
            
        if (client.getVerify() == 1) {
            builder.append("õBefhÀÀÀãpBWo");
        } else {
            builder.append("õBhÿÿÿãpBWoc");
        }
        
        //Scheint voll verbuggt zu sein... 
        builder.append('B'); // Value (Country, PLZ); A = empty, B = Deutschl., C = Öster. usw.
        builder.append("hÿÿÿã õDeutschl.õãCl      /      õcgMfÈÈúhUãEf");
        builder.append(client.getPlz()); // PLZ
        builder.append("õDhÿÿÿããf");
        builder.append(client.getJob()); // Job
        builder.append("õBhÿÿÿãf");
        builder.append(client.getSpitznamen()); // Spitzname(n)
           
        if (client.getRank() < 2) {
            builder.append("õBhÿÿÿãb");     // ohne lc  
        } else {
            builder.append("õBhÿÿÿão"); 
            builder.append("hÿÿÿã ");
            
            String lala = "";
            if(client.getLCSperre() == 1) {
                if(!client.getLC().isEmpty()) {
                    lala = "õ"+client.getLC();
                }
            } else if(client.getLCSperre() == 0) {
                if(client.getLC().isEmpty()) {
                    lala = channels.toString();
                }
            }
            
            builder.append(lala); // Auswahl lc
            builder.append("õãb");
        }
        
        builder.append("Editieren"); // Mychannel-Button Text
        builder.append("õogMfÈÈúhUãlõcgMfÈÈúhUãããSpFb ");
        builder.append("Speichern"); // Button-List, 1. Button Text
        builder.append(" õsgSfÈÈúhUãb ");
            
        if (client.getVerify() == 0) {
            builder.append("Alter verifizieren"); // Button-List, 2. Button Text
            builder.append(" õogSfÈÈúhUãb ");
        }
        
        builder.append('?'); // Button-List, 3. Button Text
        builder.append(" õogSfÈÈúhUããCpFpGACEEb");
            
        if (client.getRank() > 0) {
            builder.append("HP Edit"); // 1. Button Text (HP Edit & GB Edit)
            builder.append("õgOfÈÈúhUu");
            builder.append(String.format("/openurl %shp.php", Server.get().getURL().substring(7))); // URL (öffnen bei Klick, 1. Button)
            builder.append("õãb");
        }
            
        builder.append("Foto Edit"); // 2. Button Text (HP Edit & GB Edit)
        builder.append("õgOfÈÈúhUu");
        builder.append(String.format("/openurl %sphoto.php", Server.get().getURL().substring(7))); // URL (öffnen bei Klick, 2. Button)
        builder.append("õãããããSlõgFhUãã");

        return builder.toString();
     }
    
    public static void createMyChannelWindow(Client client) {
        StringBuilder builder = new StringBuilder();
        
        Channel channel = client.getMyChannel();

        char minStatus = 'A';
        
        if(channel.getMinRank() == 1) {
        	minStatus = 'B';
        } else if(channel.getMinRank() == 2) {
        	minStatus = 'C';
        } else if(channel.getMinRank() == 3) {
        	minStatus = 'D';
        } else if(channel.getMinRank() > 3) {
        	minStatus = 'E';
        }
        
        char gender = 'A';
        
        if(channel.getMingender() == 1) {
        	gender = 'B';
        } else if(channel.getMingender() == 2) {
        	gender = 'C';
        }
        
        char stammiMonths = 'A';
        
        if(channel.getMinstammimonths() == 1) {
        	stammiMonths = 'B';
        } else if(channel.getMinstammimonths() == 2) {
        	stammiMonths = 'C';
        } else if(channel.getMinstammimonths() == 3) {
        	stammiMonths = 'D';
        } else if(channel.getMinstammimonths() == 4) {
        	stammiMonths = 'E';
        } else if(channel.getMinstammimonths() == 5) {
        	stammiMonths = 'F';
        } else if(channel.getMinstammimonths() == 6) {
        	stammiMonths = 'G';
        } else if(channel.getMinstammimonths() == 9) {
        	stammiMonths = 'H';
        } else if(channel.getMinstammimonths() == 12) {
        	stammiMonths = 'I';
        } else if(channel.getMinstammimonths() == 18) {
        	stammiMonths = 'J';
        }
        
        builder.append("k\0Eigener Channel - GrundeinstellungenõsucõmainMyChannelõp\0ð\0\0fUhUãWl  õgMhUãEl  õgMhUãNlõgFhUãSlõgFhUãCpBWpBWpBNpBNpBNlGrundeinstellungenõgMfUhÈÈúãClõgBhUããWpGABCClNameõgMfÈÈúhUsNameõãlThemaõgMfÈÈúhUsThemaõãlZusatzinfoõgMfÈÈúhUsZusatzinfoõãlõgMfÈÈúhUãxs");
        builder.append(channel.getLoginMessage() == 1 ? 't' : 'f'); // Loginmitteilung checked
        builder.append("lLogin-MitteilungõfÈÈúgMãxs");
        builder.append(channel.getShowGender() == 1 ? 't' : 'f'); // Geschlecht anzeigen
        builder.append("lGeschlecht anzeigenõfÈÈúgMãxs");
        builder.append(channel.getShowAge() == 1 ? 't' : 'f'); // Alter anzeigen
        builder.append("lAlter anzeigenõfÈÈúgMãlõgMfÈÈúhUããCpGABCCf");
        builder.append(channel.getName());
        builder.append("õBhÿÿÿãf");
        builder.append(channel.getTopic());
        builder.append("õBhÿÿÿãf");
        builder.append(channel.getInfo());
        builder.append("õBhÿÿÿãlõcgMfÈÈúhUãlõgMfÈÈúhUãlõgMfÈÈúhUãlõgMfÈÈúhUãlõcgMfÈÈúhUãããCpBNpBNlDesignõgMfUhÈÈúãClõgBhUããWpGABCClDesignõgMfÈÈúhUsDesignõãlEigenes HintergrundbildõgMfÈÈúhUsEigenes HintergrundbildõãlDetaildesigneinstellungenõgMfÈÈúhUsDetaildesigneinstellungenõãlõgMfÈÈúhUããCpGABCCoc");
        builder.append('A'); // Eintrag (A = 1. usw.), Design Choice Value
        builder.append("Ùhÿÿÿã");
        builder.append("0815õ70erõ80erõAachenõAlienõAlternativeõAsiaõAugsburgõBadewanneõBasketballõBaWüõBayernõBeauty FarmõBerlinõBielefeldõBierõBikerõBlaue WolkenõBlubberõBlueõBlumentapeteõBochumõBodenseeõBonnõBrandenburgõBraunschweigõBremenõBroken HeartsõBücherõCanyonõCarsõChemnitzõChillenõChinatownõCocktailbarõComputerõCoolõDancingõDiscoõDortmundõDresdenõDuisburgõDüsseldorfõEastsideõElectronicõEngelõErdbeerenõEssenõEuropeõF1õFamilyõFantasiesõFarbverlaufõFlirtõFlirtextaseõFragezeichenõFrankfurtõFunõFußballõGelsenkirchenõGirls&BoysõGraue WolkenõHamburgõHandballõHandyõHannoverõHausaufgabenõHelp4YouõHerzenõHerzigõHessenõHimmelõHip HopõHitzefreiõIrrenhausõJamaicaõKaffeeõKaminzimmerõKaribikõKarlsruheõKekseõKerzenlichtõKielõKindergartenõKinoõKirschenõKleine HerzenõKnuddelsõKnutschende KnuddelsõKonsolenõKuscheleckeõKölnõLadiesõLeipzigõLeuchtturmõLiebeõLiebesengelõLiebeskummerõLiebesnestõLila WolkenõLokschuppenõLondonõLonely HeartsõLooolõLovetalkõMadridõMafiaõMafia2õMagdeburgõMagicõMamas&PapasõManga&AnimeõMannheimõMeckPommõMenõMetalõMusicõMönchengladbachõMünchenõMünsterõNachtcafeõNew YorkõNiedersachsenõNightclubõNirvanaõNRWõNürnbergõOrangeõOstfrieslandõParisõPferdeõPubõPunkõPunk 2õPuschelhasisõRapõRnBõRomõRostockõRuhrpottõRügenõSaarlandõSachsenõSachsen-AnhaltõSauerlandõSchleswig-HolsteinõSchulutensilienõSkateboardõSmileysõSmokingõSoulõSportõStandardõStarsõSternenhimmelõStuttgartõSummer FeelingõSunriseõSunshine KnuddelõTastaturõTearsõTechnoõThüringenõTierfreundeõTrauminselõTVõVampireõVerknuddelichungsinselõWeinrebeõWeiße BlütenõWestenõWestsideõWiesbadenõWolke7õWrestlingõWuppertalõ"); // Design Channels
        builder.append("ãbHochladenõsgMfÈÈúhUãbErweitertõsgMfÈÈúhUãlõcgMfÈÈúhUãããSpBNpBNpBNlMyChannel veröffentlichenõgMfUhÈÈúãClõgBhUããWpGABCCãCpGABCCããWpBNpBãWpGABCCxs");
        builder.append('t'); // LC Möglich checked
        builder.append("lLC möglichõfÈÈúgMãxs");
        builder.append('t'); // in der Whois anzeigen checked
        builder.append("lin der Whois anzeigenõfÈÈúgMããCpGABCClõgMfÈÈúhUãlõgMfÈÈúhUãããEpBNpBãWpGABCClTochterchannelsõgMfÈÈúhUsTochterchannelsõãlNotrufe EinsehenõgMfÈÈúhUsNotrufe EinsehenõããCpGABCCf");
        builder.append('9'); // Tochterchannels, TextBox Value
        builder.append("õBhÿÿÿãlõcgMfÈÈúhUãããSpFbVeröffentlichenõsgNfÈÈúhUããããCl  õgKfÈÈúhUãEpBNpBNlAdministrativesõgMfUhÈÈúãClõgBhUããWpGABCClChannelgrößeõgMfÈÈúhUsChannelgrößeõãxs");
        builder.append('t'); // Password, checked
        builder.append("lPasswortõfÈÈúgMãlChannelmoderatorenõgMfÈÈúhUsChannelmoderatorenõãlMindeststatusõgMfÈÈúhUsMindeststatusõãlGeschlechtsbeschränkungõgMfÈÈúhUsGeschlechtsbeschränkungõãlAltersbeschränkungõgMfÈÈúhUsAltersbeschränkungõãlStammimonateõgMfÈÈúhUsStammimonateõãlRegistriertageõgMfÈÈúhUsRegistriertageõãlMuten durch ButlerõgMfÈÈúhUsMuten durch Butlerõãxs");
        builder.append('t'); // Wordcheck checked
        builder.append("lWordcheckõfÈÈúgMãxs");
        builder.append('t'); // Textkügelchen checked
        builder.append("lTextkügelchenõfÈÈúgMãxs");
        builder.append('t'); // Fett & Kursiv checked
        builder.append("lFett & KursivõfÈÈúgMãxs");
        builder.append('t'); // Farbwechsel checked
        builder.append("lFarbwechselõfÈÈúgMãlSpiele: õgMfÈÈúhUsSpiele: õããCpGABCCoc");
        builder.append('L'); // 25, A = 1. Eintrag (3, Channelgröße) usw.
        builder.append("hÿÿÿã");
        builder.append("3õ4õ5õ6õ7õ8õ9õ10õ12õ15õ20õ25õ30õ35õ40õ45õ50õ60õ75õ100õ125õ150õ200õ"); // Channelgröße Auswahl
        builder.append("ãfPWõBhÿÿÿc*ãf");
        builder.append(channel.getCms().replace("||", ", ").replace("|", "")); // CMs, TextBox Value
        builder.append("õBhÿÿÿão");
        builder.append('c');
        builder.append(minStatus); // 1. Eintrag, hier: Mitglied
        builder.append("hÿÿÿãMitgliedõFamilymitgliedõStammiõEhrenmitgliedõAdminõão");
        builder.append('c');
        builder.append(gender); // 1. Eintrag, hier: Alle
        builder.append("hÿÿÿãAlleõNur männlichõNur weiblichõão");
        builder.append('c');
        builder.append('A'); // 1. Eintrag, hier: Keine Beschränkung
        builder.append("hÿÿÿãKeine BeschränkungõAb 10õAb 12õAb 14õAb 16õAb 18õAb 21õAb 25õAb 30õAb 40õAb 50õAb 60õão");
        builder.append('c');
        builder.append(stammiMonths); // 1. Eintrag, hier: 1 (Stammimonate)
        builder.append("hÿÿÿã0õ1õ2õ3õ4õ5õ6õ9õ12õ18õãohÿÿÿã0õ5õ10õ30õ60õ120õ240õ365õão");
        builder.append('c');
        builder.append('A'); // 1. Eintrag, hier: Streng
        builder.append("hÿÿÿãStrengõNormalõMildõãlõgMfÈÈúhUãlõgMfÈÈúhUãlõgMfÈÈúhUãlõgMfÈÈúhUãbEinstellungenõogMfÈÈúhUãããSpFb Speichern õsgSfÈÈúhUãlõgFhUãb Schließen õdgSfÈÈúhUããããã");

        client.send(builder.toString());
    }

    public static String playMp3(String stream) {
        PacketBuilder buffer = new PacketBuilder(SendOpcode.PLAY_MP3.getValue());

        buffer.writeByte(0x00);
        buffer.writeString(stream);

        return buffer.toString();
    }

    public static String hello(String channel) {
        PacketBuilder buffer = new PacketBuilder(SendOpcode.HELLO.getValue());

        buffer.writeByte(0x00);
        buffer.writeString("xyz"); // password key
        buffer.writeByte(0x00);
        buffer.writeString(channel);

        return buffer.toString();
    }

    public static String pong() {
        PacketBuilder buffer = new PacketBuilder(SendOpcode.PONG.getValue());

        return buffer.toString();
    }

    private static void addChannelStyle(PacketBuilder buffer, ChannelStyle style, boolean doNotLogJames) {
        buffer.writeByte(0x00);
        buffer.writeString(style.getForeground());
        buffer.writeByte(0x00);
        buffer.writeString(style.getBackground());
        buffer.writeByte(0x00);
        buffer.writeString(style.getRed());
        buffer.writeByte(0x00);
        buffer.writeString(style.getBlue());
        buffer.writeByte(0x00);
        buffer.writeString(String.valueOf(style.getFontSize()));
        buffer.writeByte(0x00);
        buffer.writeString(String.valueOf(style.getLineSpace()));
        buffer.writeByte(0x00);
        buffer.writeString(String.valueOf(style.getUserListFontSize()));
        buffer.writeByte(0x00);
        buffer.writeString(style.getBackground()); // user list
        buffer.writeByte(0x00);
        buffer.writeString(doNotLogJames?"F":"T");
        buffer.writeByte(0x00);
        buffer.writeString("-");
    }

    public static String updateChannelSettings(Channel channel) {
        PacketBuilder buffer = new PacketBuilder(SendOpcode.UPDATE_CHANNEL_SETTINGS.getValue());

        buffer.writeByte(0x00);
        buffer.writeString(channel.getName());
        addChannelStyle(buffer, channel.getStyle(), channel.getGame()!=null||channel.getSpecialEvent()==1);

        return buffer.toString();
    }

    public static String butler() {
        PacketBuilder buffer = new PacketBuilder(SendOpcode.BUTLER.getValue());

        buffer.writeByte(0x00);
        buffer.writeString(Server.get().getButler().getName());

        return buffer.toString();
    }

    public static String kick(String channel, String reason) {
        PacketBuilder buffer = new PacketBuilder(SendOpcode.KICK.getValue());

        buffer.writeByte(0x00);
        buffer.writeString(channel);
        buffer.writeByte(0x00);
        buffer.writeString(reason);

        return buffer.toString();
    }

    public static String privateChat(String channel, String nickname) {
		PacketWriter packet = new PacketWriter();
		packet.writeString(SendOpcode.MODULE.getValue());
		packet.write(0x00);
		packet.writeShort(Server.get().getModuleTree().getIndex("CLIENT_PP"));
		packet.write(channel.length());
		packet.writeString(channel);
		packet.write(nickname.length());
		packet.writeString(nickname);
		packet.write(0xFF);
		return packet.toString();
	}
    
    public static String nicklistSortTogether(String channel, String sender, String nick) {
		PacketWriter packet = new PacketWriter();
		packet.writeString(SendOpcode.MODULE.getValue());
		packet.write(0x00);
		packet.writeShort(Server.get().getModuleTree().getIndex("NICKLIST_SORT_TOGETHER"));
		packet.write((byte) channel.length());
		packet.writeString(channel);
		packet.write(0x0B);
		packet.write((byte) sender.length());
		packet.writeString(sender);
		packet.write(0x0B);
		packet.write((byte) nick.length());
		packet.writeString(nick);
		packet.write(0x0C);
		return packet.toString();
	}

    public static String channelFrame(Channel channel, String nickname) {
        PacketBuilder buffer = new PacketBuilder(SendOpcode.CHANNEL_FRAME.getValue());
        Client client = Server.get().getClient(nickname);
        buffer.writeByte(0x00);
        buffer.writeString(channel.getName());
        buffer.writeByte(0x00);
        buffer.writeString(nickname);
        buffer.writeByte(0x00);
        buffer.writeString("3"); // scrollspeed
        buffer.writeByte(0x00);
        buffer.writeString("800"); // width
        buffer.writeByte(0x00);
        buffer.writeString("600"); // height
        buffer.writeByte(0x00);
        buffer.writeString("0"); // position x
        buffer.writeByte(0x00);
        buffer.writeString("0"); // position y
        buffer.writeByte(0x00);
        buffer.writeString(channel.getBackgroundImage());
        buffer.writeByte(0x00);
        buffer.writeString(String.valueOf(channel.getBackgroundPosition()));
        buffer.writeByte(0x00);
        buffer.writeString(!client.getLC().isEmpty()?client.getLC():"-");
        addChannelStyle(buffer, channel.getStyle(), channel.getGame()!=null||channel.getSpecialEvent()==1);
        buffer.writeByte(0x00);
        buffer.writeString("T"); // channel combobox
        buffer.writeByte(0x00);
        buffer.writeString("3000"); // max. message length
        buffer.writeByte(0x00);
        buffer.writeString("T"); // help button
        buffer.writeByte(0x00);
        buffer.writeString("T"); // report button
        buffer.writeByte(0x00);
        buffer.writeString("F"); // feedback button
        buffer.writeByte(0x00);
        buffer.writeString("T"); // search button
    	

        return buffer.toString();
    }

    public static String channelList(Collection<Channel> channels, int category) {
        PacketBuilder buffer = new PacketBuilder(SendOpcode.CHANNEL_LIST.getValue());

        for (Channel channel : channels) {
        	if(channel.isVisible()) {
        		if(channel.getCategory() == category || category == 0) {
        			int count = channel.countClients();
        			buffer.writeByte(0x00);
        			buffer.writeString(channel.getName());
        			buffer.writeByte(0x0A);
        			buffer.writeString(String.valueOf(count));
        			buffer.writeByte(0x00);
        			buffer.writeByte('p');
        			buffer.writeByte(0x00);
        			buffer.writeString("B");

        			if (count == channel.getSize()) {
        				buffer.writeByte(0x00);
        				buffer.writeString("pics/icon_fullChannel.gif");
        			}

        			if (channel.getSpecialEvent() == 1) {
        				buffer.writeByte(0x00);
        				buffer.writeString("pics/icon_specialEventChannel.gif");
        			}

        			buffer.writeByte(0x00);
        			buffer.writeString("-");
        		}
        	}
        }

        return buffer.toString();
    }

    public static String switchChannel(String channelFrom, String channelTo) {
        PacketBuilder buffer = new PacketBuilder(SendOpcode.SWITCH_CHANNEL.getValue());

        buffer.writeByte(0x00);
        buffer.writeString(channelFrom);
        buffer.writeByte(0x00);
        buffer.writeString(channelTo);

        return buffer.toString();
    }

    public static String publicMessage(String sender, String channel, String message) {
        PacketBuilder buffer = new PacketBuilder(SendOpcode.PUBLIC_MESSAGE.getValue());

        Client client = Server.get().getClient(sender);
        
        buffer.writeByte(0x00);
        buffer.writeString(sender);
        buffer.writeByte(0x00);
        buffer.writeString(channel);
        buffer.writeByte(0x00);
        buffer.writeString(message);
        
        if(client.getElement() != 0) {
        	buffer.writeByte(0x00);
        	buffer.writeString(" ");
        	buffer.writeByte(0x00);
        	
        	String element;
        	int length = sender.length();

        	if(client.getElement() == 1) { // Wolke
        		element = "a";
        	} else if(client.getElement() == 2) { // Wasser
        		element = "w";
        	} else {
        		element = "e"; // Erde
        	}
        	
        	if(length > 8) {
        		buffer.writeString(String.format("°>features/elements/nick_%s-l...mx_-10.w_0.h_0.my_2.png<°°>features/elements/nick_%s-c_01...mx_13.w_0.h_0.my_2.png<°°>features/elements/nick_%s-c_02...mx_33.w_0.h_0.my_2.png<°°>features/elements/nick_%s-c_01...mx_53.w_0.h_0.my_2.png<°°>features/elements/nick_%s-r...mx_73.w_0.h_0.my_2.png<°°>{+textborder }<°", element,element,element,element,element));
        	} else if(length > 6) {
        		buffer.writeString(String.format("°>features/elements/nick_%s-l...mx_-10.w_0.h_0.my_2.png<°°>features/elements/nick_%s-c_01...mx_13.w_0.h_0.my_2.png<°°>features/elements/nick_%s-c_02...mx_33.w_0.h_0.my_2.png<°°>features/elements/nick_%s-r...mx_53.w_0.h_0.my_2.png<°  °>{+textborder }<°", element,element,element,element,element));
        	} else if(length > 4) {
        		buffer.writeString(String.format("°>features/elements/nick_%s-l...mx_-10.w_0.h_0.my_2.png<°°>features/elements/nick_%s-c_01...mx_13.w_0.h_0.my_2.png<°°>features/elements/nick_%s-r...mx_33.w_0.h_0.my_2.png<°  °>{+textborder }<°", element,element,element,element,element));
        	} else if(length > 2) {
        		buffer.writeString(String.format("°>features/elements/nick_%s-l...mx_-10.w_0.h_0.my_2.png<°°>features/elements/nick_%s-c_01...mx_13.w_0.h_0.my_2.png<°  °>{+textborder }<°", element,element,element,element,element));
        	} else {
        		buffer.writeString(String.format("°>features/elements/nick_%s-l...mx_-10.w_0.h_0.my_2.png<° °>{+textborder }<°", element,element,element,element,element));
        	}
        } else if(Server.get().getChannel(channel).getPhotos() == 1) {
            buffer.writeByte(0x00);
        
            if(!client.getPhoto().isEmpty()) {
            	buffer.writeString(String.format("photos/m/%s...quadcut_36.border_2.h_39.jpg", client.getPhoto()));
            }else {
            	if(client.getGender() == 1) {
                	buffer.writeString("msgMale...quadcut_40.mx_-2.h_39.png");
            	} else if(client.getGender() == 2) {
                	buffer.writeString("msgFemale...quadcut_40.mx_-2.h_39.png");
            	}
            }
            
            buffer.writeByte(0x00);
            buffer.writeString(sender);
            buffer.writeByte(0x00);
            buffer.writeString("0");
            buffer.writeByte(0x00);
            buffer.writeString("2");
        }
        
        return buffer.toString();
    }

    public static String updateChannelBackground(Channel channel) {
        PacketBuilder buffer = new PacketBuilder(SendOpcode.UPDATE_CHANNEL_BACKGROUND.getValue());

        buffer.writeByte(0x00);
        buffer.writeString(channel.getName());
        buffer.writeByte(0x00);
        buffer.writeString(channel.getBackgroundImage());
        buffer.writeByte(0x00);
        buffer.writeString(String.valueOf(channel.getBackgroundPosition()));

        return buffer.toString();
    }

    public static String addUser(Channel channel, Client client, Client c, boolean self) {
        PacketBuilder buffer = new PacketBuilder(SendOpcode.ADD_USER.getValue());
        Byte weight = 'p';
        
        if (self || c.checkFriend(client.getName())) {
            weight = 'b'; 
        }
        
        buffer.writeByte(0x00);
        buffer.writeString(channel.getName());
        buffer.writeByte(0x00);
        buffer.writeString(client.getName());
        
        if(client.getAge() != 0 && channel.getShowAge() == 1) {
            buffer.writeByte(0x0A);
            buffer.writeString(String.valueOf(client.getAge()));
        }
        
        buffer.writeByte(0x00);
        buffer.writeByte(weight);
        buffer.writeByte(0x00);
        buffer.writeString(channel.getStyle().getRankColor(client));

        for (Pair<String, Integer> icon : client.getIcons()) {
        	if(icon.getLeft().equals("pics/male.png") || icon.getLeft().equals("pics/female.png")) {
        		if(channel.getShowGender() == 1) {
        			buffer.writeByte(0x00);
            		buffer.writeString(icon.getLeft());
            		buffer.writeByte(0x00);
            		buffer.writeString(String.valueOf(icon.getRight()));
        		}
        	} else {
        		buffer.writeByte(0x00);
            	buffer.writeString(icon.getLeft());
            	buffer.writeByte(0x00);
            	buffer.writeString(String.valueOf(icon.getRight()));
        	}
        }
        
        if(channel.checkCm(client.getName())) {
            buffer.writeByte(0x00);
            buffer.writeString("pics/cm.png");
            buffer.writeByte(0x00);
            buffer.writeString("20");
            buffer.writeByte(0x00);
        }
        
        if(channel.checkVip(client.getName())) {
            buffer.writeByte(0x00);
            buffer.writeString("pics/icon_vip.png");
            buffer.writeByte(0x00);
            buffer.writeString("22");
            buffer.writeByte(0x00);
        }
        
        if(channel.checkMod(client.getName())) {
            buffer.writeByte(0x00);
            buffer.writeString("pics/icon_moderator.png");
            buffer.writeByte(0x00);
            buffer.writeString("24");
            buffer.writeByte(0x00);
        }
        
        if(c.getRank() > 1) {
        	if(client.getOnlineTime() < 6000) {
                buffer.writeByte(0x00);
                buffer.writeString("pics/newUser.png");
                buffer.writeByte(0x00);
                buffer.writeString("17");
                buffer.writeByte(0x00);
        	}
        }
        
        if(client.getMentor().equals(c.getName())) {
            buffer.writeByte(0x00);
            buffer.writeString("pics/schaf.png");
            buffer.writeByte(0x00);
            buffer.writeString("20");
            buffer.writeByte(0x00);
        }
        
        if(c != client && client.getSearchActivate() == 1 && c.getSearchActivate() == 1) {
        	if(c.getSearchGender().equals("männl.") && client.getGender() == 1 || c.getSearchGender().equals("weibl.") && client.getGender() == 2) {
        		buffer.writeByte(0x00);
            	buffer.writeString("pics/1.gif");
            	buffer.writeByte(0x00);
            	buffer.writeString("18");
            	buffer.writeByte(0x00);
            }
        }

        buffer.writeByte(0x00);
        buffer.writeString("-"); // login message
        buffer.writeByte(0x00);
    	buffer.writeString(client.getLastChannel() != null?client.getLastChannel():"-");
        buffer.writeByte(0x00);
        buffer.writeString(" "); 
        buffer.writeByte(0x00);
        
        if(channel.getPhotos() == 1) {
        	buffer.writeString(String.format("photos/m/%s...quadcut_36.border_2.h_39.jpg", client.getPhoto()));
        	buffer.writeByte(0x00);
        	buffer.writeString(client.getName());
        	buffer.writeByte(0x00);
        	buffer.writeString("0");
        	buffer.writeByte(0x00);
        	buffer.writeString("2");
        }
        
        return buffer.toString();
    }

    public static String addIcon(String channel, String nickname, Pair<String, Integer> icon) {
        PacketBuilder buffer = new PacketBuilder(SendOpcode.ADD_ICON.getValue());

        buffer.writeByte(0x00);
        buffer.writeString(channel);
        buffer.writeByte(0x00);
        buffer.writeString(nickname);
        buffer.writeByte(0x00);
        buffer.writeString(icon.getLeft());
        buffer.writeByte(0x00);
        buffer.writeString(String.valueOf(icon.getRight()));

        return buffer.toString();
    }

    public static String playSound(String file) {
        PacketBuilder buffer = new PacketBuilder(SendOpcode.PLAY_SOUND.getValue());

        buffer.writeByte(0x00);
        buffer.writeString(file);

        return buffer.toString();
    }

    public static String privateMessage(String sender, String recipient, String channelTo, String message, String channelFrom) {
        PacketBuilder buffer = new PacketBuilder(SendOpcode.PRIVATE_MESSAGE.getValue());

        buffer.writeByte(0x00);
        buffer.writeString(sender);
        buffer.writeByte(0x00);
        buffer.writeString(recipient);
        buffer.writeByte(0x00);
        buffer.writeString(channelTo);
        buffer.writeByte(0x00);
        buffer.writeString(message);
        buffer.writeByte(0x00);
        buffer.writeString(channelFrom);
        
        if(Server.get().getChannel(channelTo).getPhotos() == 1) {
            Client client = Server.get().getClient(sender);
            buffer.writeByte(0x00);
        
            if(!client.getPhoto().isEmpty()) {
            	buffer.writeString(String.format("photos/m/%s...quadcut_36.border_2.h_39.jpg", client.getPhoto()));
            } else {
            	if(client.getGender() == 1) {
                	buffer.writeString("msgMale...quadcut_40.mx_-2.h_39.png");
            	} else if(client.getGender() == 2) {
                	buffer.writeString("msgFemale...quadcut_40.mx_-2.h_39.png");
            	}
            }
            
            buffer.writeByte(0x00);
            buffer.writeString(sender);
            buffer.writeByte(0x00);
            buffer.writeString("0");
            buffer.writeByte(0x00);
            buffer.writeString("2");
        }

        return buffer.toString();
    }

    public static String action(String sender, String channel, String message) {
        PacketBuilder buffer = new PacketBuilder(SendOpcode.ACTION.getValue());

        buffer.writeByte(0x00);
        buffer.writeString(sender);
        buffer.writeByte(0x00);
        buffer.writeString(channel);
        buffer.writeByte(0x00);
        buffer.writeString(message);
        
        if(Server.get().getChannel(channel).getPhotos() == 1) {
        	if(!sender.equals("°BB°") && !sender.equals("°BB°_>>>")) {
            Client client = Server.get().getClient(sender);
            buffer.writeByte(0x00);
        
            if(!client.getPhoto().isEmpty() && !sender.isEmpty()) {
            	buffer.writeString(String.format("photos/m/%s...quadcut_36.border_2.h_39.jpg", client.getPhoto()));
            } else {
            	if(client.getGender() == 1) {
                	buffer.writeString("msgMale...quadcut_40.mx_-2.h_39.png");
            	} else if(client.getGender() == 2) {
                	buffer.writeString("msgFemale...quadcut_40.mx_-2.h_39.png");
            	}
            }
            
            buffer.writeByte(0x00);
            buffer.writeString(sender);
            buffer.writeByte(0x00);
            buffer.writeString("0");
            buffer.writeByte(0x00);
            buffer.writeString("2");
        	}
        }

        return buffer.toString();
    }
    
    public static String picAction(String sender, String channel, String message, String pic) {
        if (!pic.startsWith("icons/") && !pic.isEmpty()) {
            pic = String.format("icons/%s", pic);
        }
        
        PacketBuilder buffer = new PacketBuilder(SendOpcode.ACTION.getValue());

        buffer.writeByte(0x00);
        buffer.writeString(sender);
        buffer.writeByte(0x00);
        buffer.writeString(channel);
        buffer.writeByte(0x00);
        buffer.writeString(message);
        buffer.writeByte(0x00);
        buffer.writeString(pic);
        buffer.writeByte(0x00);
        buffer.writeString(" ");
        buffer.writeByte(0x00);
        buffer.writeString("1");
        buffer.writeByte(0x00);
        buffer.writeString("0");

        return buffer.toString();
    }

    public static String userList(Channel channel, Client c) {
        PacketBuilder buffer = new PacketBuilder(SendOpcode.USER_LIST.getValue());

        buffer.writeByte(0x00);
        buffer.writeString(channel.getName());

        for (Client client : channel.getClients()) {
        	String drauf = "0";
        	
            if(c.checkFriend(client.getName())) {
                drauf = "1";
            }
            
            buffer.writeByte(0x00);
            buffer.writeString(client.getName());
            
            if(client.getAge() != 0 && channel.getShowAge() == 1) {
                buffer.writeByte(0x0A);
                buffer.writeString(String.valueOf(client.getAge()));
            }
            
            buffer.writeByte(0x00);
            if (drauf.equals("1")) {
                buffer.writeByte('b');
            } else {
                buffer.writeByte('p');
            }
            buffer.writeByte(0x00);
            buffer.writeString(channel.getStyle().getRankColor(client));

            for (Pair<String, Integer> icon : client.getIcons()) {
            	if(icon.getLeft().equals("pics/male.png") || icon.getLeft().equals("pics/female.png")) {
            		if(channel.getShowGender() == 1) {
            			buffer.writeByte(0x00);
                		buffer.writeString(icon.getLeft());
                		buffer.writeByte(0x00);
                		buffer.writeString(String.valueOf(icon.getRight()));
            		}
            	} else {
            		buffer.writeByte(0x00);
                	buffer.writeString(icon.getLeft());
                	buffer.writeByte(0x00);
                	buffer.writeString(String.valueOf(icon.getRight()));
            	}
            }
            
            if(channel.checkCm(client.getName())) {
                buffer.writeByte(0x00);
                buffer.writeString("pics/cm.png");
                buffer.writeByte(0x00);
                buffer.writeString("20");
                buffer.writeByte(0x00);
            }
            
            if(channel.checkVip(client.getName())) {
                buffer.writeByte(0x00);
                buffer.writeString("pics/icon_vip.png");
                buffer.writeByte(0x00);
                buffer.writeString("22");
                buffer.writeByte(0x00);
            }
            
            if(channel.checkMod(client.getName())) {
                buffer.writeByte(0x00);
                buffer.writeString("pics/icon_moderator.png");
                buffer.writeByte(0x00);
                buffer.writeString("24");
                buffer.writeByte(0x00);
            }
            
            if(c.getRank() > 1) {
            	if(client.getOnlineTime() < 6000) {
                    buffer.writeByte(0x00);
                    buffer.writeString("pics/newUser.png");
                    buffer.writeByte(0x00);
                    buffer.writeString("17");
                    buffer.writeByte(0x00);
            	}
            }
            
            if(client.getMentor().equals(c.getName())) {
                buffer.writeByte(0x00);
                buffer.writeString("pics/schaf.png");
                buffer.writeByte(0x00);
                buffer.writeString("20");
                buffer.writeByte(0x00);
            }
            
            if(client.getSearchActivate() == 1 && c.getSearchActivate() == 1) {
            	if(c.getSearchGender().equals("männl.") && client.getGender() == 1 || c.getSearchGender().equals("weibl.") && client.getGender() == 2) {
            		buffer.writeByte(0x00);
                	buffer.writeString("pics/1.gif");
                	buffer.writeByte(0x00);
                	buffer.writeString("18");
                	buffer.writeByte(0x00);
                }
            }

            buffer.writeByte(0x00);
            buffer.writeString("-");
        }

        return buffer.toString();
    }

    public static String removeUser(Client client, Channel c) {
        PacketBuilder buffer = new PacketBuilder(SendOpcode.REMOVE_USER.getValue());
        
        buffer.writeByte(0x00);
        buffer.writeString(client.getName());
        buffer.writeByte(0x00);
        buffer.writeString(c.getName());
    	buffer.writeByte(0x00);
        buffer.writeString(client.getNewChannel() != null && !client.getChannel().getName().equals(client.getNewChannel()) && client.getChannels().size() < 2?client.getNewChannel():"-");
        
        if(c.getPhotos() == 1) {
        	buffer.writeByte(0x00);
        	buffer.writeString(" ");
        	buffer.writeString(String.format("photos/m/%s...quadcut_36.border_2.h_39.jpg", client.getPhoto()));
        	buffer.writeByte(0x00);
        	buffer.writeString(client.getName());
        	buffer.writeByte(0x00);
        	buffer.writeString("0");
        	buffer.writeByte(0x00);
        	buffer.writeString("2");
        }
        
        if(!c.isVisible() && c.getTemp() == 1 && c.countClients() < 2 || !c.getTochter().isEmpty() && c.countClients() < 2) {
			Server.removeChannel(c.getName());
        	Server.get().query(String.format("delete from channels where name='%s'", c.getName()));
        }

        return buffer.toString();
    }

    public static String openURL(String url, String target) {
        PacketBuilder buffer = new PacketBuilder(SendOpcode.OPEN_URL.getValue());

        buffer.writeByte(0x00);
        buffer.writeString(url);
        buffer.writeByte(0x00);
        buffer.writeString(target);

        return buffer.toString();
    }

    public static String removeIcon(String channel, String nickname, String icon) {
        PacketBuilder buffer = new PacketBuilder(SendOpcode.REMOVE_ICON.getValue());

        buffer.writeByte(0x00);
        buffer.writeString(channel);
        buffer.writeByte(0x00);
        buffer.writeString(nickname);
        buffer.writeByte(0x00);
        buffer.writeString(icon);

        return buffer.toString();
    }
}