/* 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 netchat;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import tools.IntegerUtil;

import tools.KCodeParser;
import tools.Logger;
import tools.PacketCreator;
import tools.Pair;
import tools.database.ConnectionPool;
import tools.database.PoolConnection;

public class Client {
	private final List<Channel> channels;
	private final Socket socket;
	private OutputStream out;
	private List<Pair<String, Integer>> icons;
	private byte rank, gender, messageSound;
	private float wordmixPoints;
	private byte emailVerify;
	private byte emails;
	private byte tutOpen;
	private String authPassword;
	private byte authActive;
	private String sysInfo;
	private byte aktuTut;
	private byte tutAktiv;
	private int element;
	private int tutopen;
	private byte knuddelscentLevel;
	private int forumCon;
	private byte knuddelscentLock;
	private byte readmeEffects;
	private byte newPhotoComment;
	private byte snp;
	private byte agePlus;
	private byte childJuSchuMessage;
	private byte warnings = 1;
	private byte kissed;
	private int dmWin;
	private int dmStartKnuddels;
	private int dm;
	private byte sun;
	private byte sunLock;
	private byte weckMessage;
	private byte bazookasperre;
	private byte butterflysperre;
	private byte flyingbedsperre;
	private byte winksperre;
	private byte immunsperre;
	private byte healsperre;
	private byte heartMessage;
	private int kontoKnuddels;
	private byte mpChat;
	private byte mpFriendlist;
        private float knuddels;
	private byte belohnen;
	private int timeMonth;
	private int timeDay;
	private byte lcmonths;
	private byte holknuddelsrunde;
	private int thiefGame;
	private int hol; 
	private byte highOrLowNumber;
	private byte persofalsch;
	private byte analysedatasperre;
	private int kicks;
        private int locks;
	private byte showEffects;
	private byte sexysperre;
	private byte faSort;
	private int admincallFirst;
	private int admincallSecond;
	private int admincallThird;
	private int erhalten;
	private int verschenkt;
	private byte holrunde;
	private int aufrufe;
	private byte photoVerify;
	private int jumpopunkte;
	private byte kissall;
	private byte silence;
	private byte dreamsperre;
	private byte starlitesperre;
	private byte friendssperre;
	private byte loginCategory;
	private byte verify;
	private byte heartsperre;
	private byte grippestatus;
	private byte newssperre;
	private int lotto;
	private int roses;
	private byte rosesSend;
	private int flames;
	private int cmutes;
	private int mutes;
	private int cls;
	private int zeichen;
	private byte lcsperre;
	private byte searchAgeFrom;
	private byte searchAgeUntil;
	private byte showEmail;
	private byte showZodiac;
	private byte showBirthday;
	private byte searchActivate;
	private byte effect;
	private byte mask;
	private int mentorPoints;
	private int id;
	private int kisses;
	private byte age;
	private byte spam;
	private int onlineTime;
	private int adminTime;
	private byte pfLeben;
	private long coin;
	private long wahlsperre;
	private long pfGeworfen;
	private long botkontrolleZeit;
	private long sperre;
        private long disable;
        private long deletenick;
	private long spielsperre;
	private long notrufsperre;
	private long lastOnline;
	private long timeOut;
	private long loginTimestamp;
	private long lastAction;
	private long login;
	private String missed;
	private String like;
	private String holdhands;
	private String smileys;
	private String zusammen;
	private String host;
	private String coinchannel;
	private String botkontrolleAn;
	private String botkontrolleVon;
	private String color;
	private String agent;
	private String kontoPassword;
	private String sperreinfo;
	private String sperrevon;
	private String heart;
	private String photo;
	private String newChannel;
	private String lastChannel;
	private String deny;
	private String schuetzlinge;
	private String stammiwhen;
	private String cmwhen;
	private String uPassword;
	private String quizrang;
	private String spitznamen;
	private String mentor = "";
	private String javaVersion;
	private String desc;
	private String plz;
	private String plzLand;
	private String comments;
	private String cmcomments;
	private String teams;
	private String friendlist;
	private String appletVersion;
	private String career;
	private String profile;
	private String date;
	private String awayReason;
	private String name;
	private String dream;
	private String friends;
	private String registerIP;
	private String lc;
	private String birthday;
	private String vergeben;
	private String searchGender;
	private String searchEntfernung;
	private String searchMotiv;
	private String email;
	private String signatur;
	private String lastOnlineChannel;
	private String readme;
	private String password;
	private String realname;
	private String stadt;
	private String land;
	private String hobbys;
	private String job;
	private String motto;
	private String registrationDate;
	private String registrationTime;
	private String ipAddress;
	private String ignoredNicks;
	
	public Map<Long, String> readmes = new HashMap<Long, String>();
	public List<String[]> logins = new ArrayList<String[]>();
	public List<String[]> newRoses = new ArrayList<String[]>();
	public List<String[]> rosen = new ArrayList<String[]>();
	public List<String[]> admincalls = new ArrayList<String[]>();
	public List<String> receivedHearts = new ArrayList<String>();
	public List<String[]> oldMessages = new ArrayList<String[]>();
	public List<String[]> sentMessages = new ArrayList<String[]>();
	public List<String[]> newMessages = new ArrayList<String[]>();
	
	public int getWarnings() {
		return warnings;
	}

	public int existBlindDate() {
		int exist = 0;

		PoolConnection pcon = ConnectionPool.getConnection();
		PreparedStatement ps = null;

		try {
			Connection con = pcon.connect();
			ps = con.prepareStatement("SELECT `id`,`user` FROM `blinddate` WHERE `user` = ?");
			ps.setString(1, name);
			ResultSet rs = ps.executeQuery();

			if (rs.next()) {
				exist = 1;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			if (ps != null) {
				try {
					ps.close();
				} catch (SQLException e) {
				}
			}

			pcon.close();
		}

		return exist;
	}

	public void increaseWarnings() {
		warnings++;
	}

	public void setAdminTime(int adminTime) {
		this.adminTime = adminTime;
	}

	public void setWarnings(byte warnings) {
		this.warnings = warnings;
	}

	public long getLogin() {
		return login;
	}

	public void activateSmiley(int cat) {
		Long systemtime = System.currentTimeMillis() / 1000;
		long end = systemtime + 604800;
		StringBuilder smileys = new StringBuilder();
		int codeActivatedCategory = cat;
		String basicReplacement = "", basicName = "", basicSyntax = "", basicDescription = "";
		int basic = 1, basicID = 0;

		for (int smileyID : Server.smileys.keySet()) {
			String[] split = Server.smileys.get(smileyID);
			int category = Integer.parseInt(split[2]);
			String replacement = split[1];

			if (category == codeActivatedCategory) {
				if (basic == 1) {
					basicReplacement = replacement;
					basicSyntax = split[0];
					basicName = split[3];
					basicDescription = split[4];
					basicID = smileyID;
				} else {
					smileys.append("°>").append(replacement).append("<°");
				}

				basic++;
			}
		}

		Server.get().newMessage(
						Server.get().getButler(),
						name,
						"Code aktiviert",
						String.format(
								"Hallo %s,##meinen herzlichen Glückwunsch, du hast deinen Code erfolgreich aktiviert:##Soeben wurde der Smiley °>%s<° (_%s_) aktiviert. Ab jetzt wird die Eingabe _%s_ durch diesen Smiley ersetzt.#°>%s<° = %s##%s##Bei Eingabe von °BB°_°>/code ?|/code ?<°_°r° erhältst du eine Übersicht deiner Codes.##Ich wünsche dir viel Vergnügen mit deinem neuen Smiley,##dein James",
								getName(), basicReplacement, basicName,
								basicSyntax, basicReplacement, basicSyntax,
								basicDescription,
								Server.get().timeStampToDate(end),
								smileys.toString(), Server.get().getButler()
										.getName()), System.currentTimeMillis()/1000);
		setErhalten(getErhalten() + 1);
		setSmileys(String.format("%s|%s~%s|", getSmileys(), basicID, end));
	}
	
	public void setLogin(long login) {
		this.login = login;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getLoginCategory() {
		return loginCategory;
	}

	public void setLoginCategory(byte loginCategory) {
		this.loginCategory = loginCategory;
	}

	private int scrollspeed, cmTestQuestion, cmTestWrong;

	public int getCmTestQuestion() {
		return cmTestQuestion;
	}

	public void setCmTestQuestion(int cmTestQuestion) {
		this.cmTestQuestion = cmTestQuestion;
	}

	public int getCmTestWrong() {
		return cmTestWrong;
	}

	public boolean checkCl(Channel channel) {
		return channel.getCls().contains(String.format("|%s|", name));
	}

	public int getDm() {
		return dm;
	}

	public void setDm(int dm) {
		this.dm = dm;
	}

	public int getElement() {
		return element;
	}

	public void setElement(int element) {
		this.element = element;
	}

	public void setCmTestWrong(int cmTestWrong) {
		this.cmTestWrong = cmTestWrong;
	}

	public int getScrollspeed() {
		return scrollspeed;
	}
	
	 public void CheckNewTut(String cmd, Channel channel, int aktututs)
	 /*      */   {
	 /*  714 */     String aktuheader = "";
	 /*  715 */     String aktufunktion = "";
	 /*  716 */     PoolConnection pcon98 = ConnectionPool.getConnection(); PreparedStatement ps98 = null;
	 /*      */     try { Connection con98 = pcon98.connect();
	 /*  717 */       ps98 = con98.prepareStatement(new StringBuilder().append("SELECT * FROM tutorials where tutid = '").append(aktututs).append("'").toString());
	 /*  718 */       for (ResultSet rs98 = ps98.executeQuery(); rs98.next(); aktuheader = rs98.getString("titel")) aktufunktion = rs98.getString("funktion");  } catch (SQLException e) {
	 /*  718 */       e.printStackTrace(); } finally { if (ps98 != null) try { ps98.close(); } catch (SQLException e) {
	 /*      */         } pcon98.close(); }
	 /*  719 */     String nextheader = "";
	 /*  721 */     PoolConnection pcon97 = ConnectionPool.getConnection(); PreparedStatement ps97 = null;
	 /*      */     try { Connection con97 = pcon97.connect();
	 /*  722 */       ps97 = con97.prepareStatement(new StringBuilder().append("SELECT * FROM tutorials where tutid = '").append(aktututs + 1).append("'").toString());
	 /*  723 */       for (ResultSet rs97 = ps97.executeQuery(); rs97.next(); nextheader = rs97.getString("titel"));  } catch (SQLException e) {
	 /*  723 */       e.printStackTrace(); } finally { if (ps97 != null) try { ps97.close(); } catch (SQLException e) {
	 /*      */         } pcon97.close(); }
	 /*  724 */     int use = 0;
	 /*      */ 
	 /*  726 */     if (!aktufunktion.isEmpty()) {
	 /*  727 */       String[] lol = aktufunktion.split(";");
	 /*      */ 
	 /*  729 */       for (String item : lol) {
	 /*  730 */         String command = KCodeParser.escape(item.substring(1).split(" ")[0]);
	 /*  731 */         if (item.equals(cmd)) {
	 /*  732 */           use = 1;
	 /*      */         }
	 /*  734 */         if (command.equals(item)) {
	 /*  735 */           use = 1;
	 /*      */         }
	 /*      */       }
	 /*      */     }
	 /*      */ 
	 /*  740 */     if ((use == 1) && (!aktufunktion.isEmpty()) && (this.tutopen == 0) && (this.tutAktiv == 1)) {
	 /*  741 */       sendButlerMessage(channel.getName(), String.format(new StringBuilder().append("Du hast soeben erfolgreich die TuT-Lektion ''").append(aktuheader).append("'' abgeschlossen. Als nächstes erwartet dich die Lektion ''").append(nextheader).append("''.").toString(), new Object[0]));
	 /*  742 */       this.tutopen = 1;
	 /*  743 */       this.aktuTut += 1;
	 /*      */     }
	 /*      */ 
	 /*  747 */     if ((aktufunktion.isEmpty()) && (!nextheader.isEmpty()) && (this.tutopen == 0) && (this.tutAktiv == 1)) {
	 /*  748 */       this.tutopen = 1;
	 /*  749 */       this.aktuTut += 1;
	 /*      */     }
	 /*      */   }

	public void setScrollspeed(int scrollspeed) {
		this.scrollspeed = scrollspeed;
	}

	private String kdiice_dice, starsFrom, starsTo;

	public int getBazookasperre() {
		return bazookasperre;
	}

	public boolean hasPermission(String permission) {
		if (Server.permissions.containsKey(permission)) {
			String keys = Server.permissions.get(permission);

			for (String key : keys.split("\\|")) {
				if (!key.isEmpty()) {
					if (key.equals(String.format("N%s", name))) {
						return true;
					} else if (key.startsWith("S")) {
						int smiley = Integer.parseInt(key.substring(1));

						if (smileys.contains(String.format("|%s~", smiley))) {
							return true;
						}
					} else if (key.startsWith("TM")) {
						String team = key.substring(2);

						if (checkTeam(team)) {
							return true;
						}
					} else if (key.startsWith("TL")) {
						String team = key.substring(2);

						if (checkTeamLeader(team)) {
							return true;
						}
					} else if (key.startsWith("R")) {
						int status = Integer.parseInt(key.substring(1));

						if (rank >= status) {
							return true;
						}
					}
				}
			}
		}

		return false;
	}

	public void setBazookasperre(byte bazookasperre) {
		this.bazookasperre = bazookasperre;
	}

	public int getButterflysperre() {
		return butterflysperre;
	}

	public void setButterflysperre(byte butterflysperre) {
		this.butterflysperre = butterflysperre;
	}

	public String getStarsFrom() {
		return starsFrom;
	}

	public int getAufrufe() {
		return aufrufe;
	}

	public int getEmailVerify() {
		return emailVerify;
	}

	public void setEmailVerify(byte emailVerify) {
		this.emailVerify = emailVerify;
	}

	public void increaseAufrufe() {
		aufrufe++;
	}

	public int getBelohnen() {
		return belohnen;
	}

	public void setBelohnen(byte belohnen) {
		this.belohnen = belohnen;
	}

	public long getCoin() {
		return coin;
	}

	public void setCoin(long coin) {
		this.coin = coin;
	}

	public int getWeckMessage() {
		return weckMessage;
	}

	public void setWeckMessage(byte weckMessage) {
		this.weckMessage = weckMessage;
	}

	public int getFlyingbedsperre() {
		return flyingbedsperre;
	}

	public void setRosensperre(String string) {
		this.rosesSend = Byte.parseByte(string);
	}
        
        public void setRosensperre(byte rosenSperre) {
		this.rosesSend = rosenSperre;
	}

	public String getRosensperre() {
		if (rosesSend > 0) {
			return "1";
		}

		return "0";
	}

	public void setFlyingbedsperre(byte flyingbedsperre) {
		this.flyingbedsperre = flyingbedsperre;
	}

	public int getWinksperre() {
		return winksperre;
	}

	public byte getAuthActive() {
		return authActive;
	}

	public void setAuthActive(byte authActive) {
		this.authActive = authActive;
	}

	public String getSmileys() {
		return smileys;
	}

	public void setSmileys(String smileys) {
		this.smileys = smileys;
	}

	public void setWinksperre(byte winksperre) {
		this.winksperre = winksperre;
	}

	public void setStarsFrom(String starsFrom) {
		this.starsFrom = starsFrom;
	}

	public int getDmWin() {
		return dmWin;
	}

	public void setDmWin(int dmWin) {
		this.dmWin = dmWin;
	}

	public int getKissall() {
		return kissall;
	}

	public int getChildJuSchuMessage() {
		return childJuSchuMessage;
	}

	public void setChildJuSchuMessage(byte childJuSchuMessage) {
		this.childJuSchuMessage = childJuSchuMessage;
	}

	public void setKissall(byte kissall) {
		this.kissall = kissall;
	}

	public int getHeartMessage() {
		return heartMessage;
	}

	public int getHealsperre() {
		return healsperre;
	}

	public void setHealsperre(byte healsperre) {
		this.healsperre = healsperre;
	}

	public void setHeartMessage(byte heartMessage) {
		this.heartMessage = heartMessage;
	}

	public int getHighOrLowRound() {
		return holrunde;
	}

	public String getCoinchannel() {
		return coinchannel;
	}

	public void setCoinchannel(String coinchannel) {
		this.coinchannel = coinchannel;
	}

	public int getHighOrLowNumber() {
		return highOrLowNumber;
	}

	public void setHighOrLowNumber(byte highOrLowNumber) {
		this.highOrLowNumber = highOrLowNumber;
	}

	public String getHost() {
		return host;
	}

	public void setHighOrLowRound(byte highOrLowRound) {
		this.holrunde = highOrLowRound;
	}

	public void increaseHighOrLowRound() {
		holrunde++;
	}

	public String getZusammen() {
		return zusammen;
	}

	public void setZusammen(String zusammen) {
		this.zusammen = zusammen;
	}

	public String getStarsTo() {
		return starsTo;
	}

	public void setStarsTo(String starsTo) {
		this.starsTo = starsTo;
	}

	public String getDiice() {
		return kdice_dice;
	}

	public String getAgent() {
		return agent;
	}

	public long getWahlsperre() {
		return wahlsperre;
	}

	public void setWahlsperre(long wahlsperre) {
		this.wahlsperre = wahlsperre;
	}

	public boolean checkCode(int smiley) {
		return smileys.contains(String.format("|%s~", smiley));
	}

	public int getPersofalsch() {
		return persofalsch;
	}

	public String getAuthPassword() {
		return authPassword;
	}

	public void setAuthPassword(String authPassword) {
		this.authPassword = authPassword;
	}

	public void increasePersofalsch() {
		persofalsch++;
	}
	
	public void setWordMixPoints(float wordMixPoints) {
		this.wordmixPoints = wordMixPoints;
	}

	public String getHeart() {
		return heart;
	}

	public void setHeart(String heart) {
		this.heart = heart;

		PoolConnection pcon = ConnectionPool.getConnection();
		PreparedStatement ps = null;

		try {
			Connection con = pcon.connect();
			ps = con.prepareStatement("update accounts set heart = ? where name = ?");
			ps.setString(1, heart);
			ps.setString(2, name);
			ps.execute();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			if (ps != null) {
				try {
					ps.close();
				} catch (SQLException e) {
				}
			}

			pcon.close();
		}
	}

	public String getColor() {
		return color;
	}

	public void setColor(String color) {
		this.color = color;
	}

	public int getPfLeben() {
		return pfLeben;
	}

	public int getLcmonths() {
		return lcmonths;
	}

	public void setLcmonths(byte lcmonths) {
		this.lcmonths = lcmonths;
	}

	public void setPfLeben(byte pfLeben) {
		this.pfLeben = pfLeben;
	}

	public int getKontoKnuddels() {
		return kontoKnuddels;
	}

        public float getKnuddels() {
		return knuddels;
	}
        
	public Channel getMyChannel() {
		for (Channel channel : Server.get().getChannels()) {
			if (channel.getOwner().equals(name)) {
				return channel;
			}
		}

		return null;
	}

	public void setKontoKnuddels(int kontoKnuddels) {
		this.kontoKnuddels = kontoKnuddels;
	}
        
        public void setKnuddels(int knuddels) {
		this.knuddels = knuddels;
	}
        
         public void setKisses(int kisses) {
		this.kisses = kisses;
	}
        
        public void setonlineTime(int onlinetime) {
		this.onlineTime = onlinetime;
	}

	public long getPfGeworfen() {
		return pfGeworfen;
	}

	public void setPfGeworfen(long pfGeworfen) {
		this.pfGeworfen = pfGeworfen;
	}

	public String getKontoPassword() {
		return kontoPassword;
	}

	public long getBotkontrolleZeit() {
		return botkontrolleZeit;
	}

	public void setBotkontrolleZeit(long botkontrolleZeit) {
		this.botkontrolleZeit = botkontrolleZeit;
	}

	public String getBotkontrolleAn() {
		return botkontrolleAn;
	}

	public void setBotkontrolleAn(String botkontrolleAn) {
		this.botkontrolleAn = botkontrolleAn;
	}

	public String getBotkontrolleVon() {
		return botkontrolleVon;
	}

	public void setBotkontrolleVon(String botkontrolleVon) {
		this.botkontrolleVon = botkontrolleVon;
	}

	public void setMissed(String missed) {
		this.missed = missed;
	}

	public String getMissed() {
		return missed;
	}

	public byte getAktuTut() {
		return aktuTut;
	}

	public void setAktuTut(byte aktuTut) {
		this.aktuTut = aktuTut;
	}

	public void setKontoPassword(String kontoPassword) {
		this.kontoPassword = kontoPassword;
	}

	public int getVerify() {
		return verify;
	}

	public byte getTutOpen() {
		return tutOpen;
	}

	public void setTutOpen(byte tutOpen) {
		this.tutOpen = tutOpen;
	}

	public void setVerify(byte verify) {
		this.verify = verify;
	}

	public String getMentor() {
		return mentor;
	}

	public long getSperre() {
		return sperre;
	}
        
        public long getDisable() {
		return disable;
	}
        
        public long getDeletenick() {
		return deletenick;
	}

	public int getKnuddelscentLevel() {
		return knuddelscentLevel;
	}

	public void setKnuddelscentLevel(byte knuddelscentLevel) {
		this.knuddelscentLevel = knuddelscentLevel;
	}

	public int getKnuddelscentLock() {
		return knuddelscentLock;
	}

	public void setKnuddelscentLock(byte knuddelscentLock) {
		this.knuddelscentLock = knuddelscentLock;
	}

	public void setSperre(long sperre) {
		this.sperre = sperre;
	}

        public void setDisable(long disable) {
		this.disable = disable;
	}
        
        public void setDeletenick(long deletenick) {
		this.deletenick = deletenick;
	}
        
        
	public String getSperreinfo() {
		return sperreinfo;
	}

	public void setSperreinfo(String sperreinfo) {
		this.sperreinfo = sperreinfo;
	}

	public String getSperrevon() {
		return sperrevon;
	}

	public void setSperrevon(String sperrevon) {
		this.sperrevon = sperrevon;
	}

	public void setMentor(String mentor) {
		this.mentor = mentor;
	}

	public int getMpChat() {
		return mpChat;
	}

	public byte getMessageSound() {
		return messageSound;
	}

	public void setMessageSound(byte messageSound) {
		this.messageSound = messageSound;
	}

	public void setMpChat(byte mpChat) {
		this.mpChat = mpChat;
	}

	public int getMpFriendlist() {
		return mpFriendlist;
	}

	public void setMpFriendlist(byte mpFriendlist) {
		this.mpFriendlist = mpFriendlist;
	}

	public byte getTutAktiv() {
		return tutAktiv;
	}

	public void setTutAktiv(byte tutAktiv) {
		this.tutAktiv = tutAktiv;
	}

	public String getJavaVersion() {
		return javaVersion;
	}

	public void setJavaVersion(String javaVersion) {
		this.javaVersion = javaVersion;
	}

	public String getHoldHands() {
		return holdhands;
	}

	public void setHoldHands(String holdhands) {
		this.holdhands = holdhands;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public int getDmStartKnuddels() {
		return dmStartKnuddels;
	}

	public void setDmStartKnuddels(int dmStartKnuddels) {
		this.dmStartKnuddels = dmStartKnuddels;
	}

	public String getPlz() {
		return plz;
	}

	public void setPlz(String plz) {
		this.plz = plz;
	}

	public String getPlzLand() {
		return plzLand;
	}

	public void setPlzLand(String plzLand) {
		this.plzLand = plzLand;
	}

	public String getComments() {
		return comments;
	}

	public int getThiefGame() {
		return thiefGame;
	}

	public void setThiefGame(int thiefGame) {
		this.thiefGame = thiefGame;
	}
	
	public String getDeny() {
		return deny;
	}

	public int getSnp() {
		return snp;
	}

	public void setSnp(byte snp) {
		this.snp = snp;
	}

	public void setDeny(String deny) {
		this.deny = deny;
	}

	public int getSun() {
		return sun;
	}

	public void setSun(byte sun) {
		this.sun = sun;
	}

	public int getSunLock() {
		return sunLock;
	}

	public int getNewPhotoComment() {
		return newPhotoComment;
	}

	public void setNewPhotoComment(byte newPhotoComment) {
		this.newPhotoComment = newPhotoComment;
	}

	public void setSunLock(byte sunLock) {
		this.sunLock = sunLock;
	}

	public int getAgePlus() {
		return agePlus;
	}

	public void setAgePlus(byte agePlus) {
		this.agePlus = agePlus;
	}

	public void setComments(String comments) {
		this.comments = comments;
	}

	public String getCmcomments() {
		return cmcomments;
	}

	public void setCmcomments(String cmcomments) {
		this.cmcomments = cmcomments;
	}

	public String getFriendlist() {
		return friendlist;
	}

	public long getNotrufsperre() {
		return notrufsperre;
	}

	public void setNotrufsperre(long notrufsperre) {
		this.notrufsperre = notrufsperre;
	}

	public int getAnalysedatasperre() {
		return analysedatasperre;
	}

	public void setAnalysedatasperre(byte analysedatasperre) {
		this.analysedatasperre = analysedatasperre;
	}

	public void setFriendlist(String friendlist) {
		this.friendlist = friendlist;
	}

	public String getTeams() {
		return teams;
	}

	public String getNewChannel() {
		return newChannel;
	}

	public void setNewChannel(String newChannel) {
		this.newChannel = newChannel;
	}

	public void setCmComment(String von, String text, String comment) {
		Client target = Server.get().getClient(getName());
		comment = comment.replace("'", "\'");
		boolean online = true;
		String uhrzeit = String
				.format("%s %s",
						Server.get().timeStampToDate(
								System.currentTimeMillis() / 1000),
						Server.get().timeStampToTime(
								System.currentTimeMillis() / 1000));

		if (target == null) {
			online = false;
			target = new Client(null);
			target.loadStats(getName());
		}

		if (online) {
			target.setCmcomments(String.format("%s|%s°s9,°%s°s9,°%s|", von,
					target.getCmcomments(),
					text != null ? String.format("\"_%s_\" %s", text, comment)
							: comment, uhrzeit));
		} else {
			Server.get()
					.query(String
							.format("UPDATE `accounts` SET `cmcomments` = '%s|%s°s9,°%s°s9,°%s|' WHERE `name` = '%s'",
									von,
									target.getCmcomments(),
									text != null ? String.format("\"_%s_\" %s",
											text, comment) : comment, uhrzeit,
									getName()));
		}
	}

	public void setTeams(String teams) {
		this.teams = teams;
	}

	public boolean checkFriend(String nick) {
		return getFriendlist().contains(String.format("|%s|", nick));
	}

	public boolean checkSchuetzling(String nick) {
		return getSchuetzlinge().contains(String.format("|%s|", nick));
	}

	public int getHeartsperre() {
		return heartsperre;
	}

	public void setHeartsperre(byte heartsperre) {
		this.heartsperre = heartsperre;
	}

	public int getReadmeEffects() {
		return readmeEffects;
	}

	public void setReadmeEffects(byte readmeEffects) {
		this.readmeEffects = readmeEffects;
	}

	public int getHolknuddelsrunde() {
		return holknuddelsrunde;
	}

	public void setHolknuddelsrunde(byte holknuddelsrunde) {
		this.holknuddelsrunde = holknuddelsrunde;
	}

	public String getuPassword() {
		return uPassword;
	}

	public void setuPassword(String uPassword) {
		this.uPassword = uPassword;
	}

	public String getCareer() {
		return career;
	}

	public int getGrippeStatus() {
		return grippestatus;
	}

	public void setGrippeStatus(byte i) {
		this.grippestatus = i;
	}

	public void setCareer(String career) {
		this.career = career;
	}

	public String getAppletVersion() {
		return appletVersion;
	}

	public void setAppletVersion(String version) {
		this.appletVersion = version;
	}

	public int getKicks() {
		return kicks;
	}
        
        public int getLocks() {
		return locks;
	}

	public void setKicks(int kicks) {
		this.kicks = kicks;
	}
        
        public void setLocks(int locks) {
		this.locks = locks;
	}

	public String getProfile() {
		return profile;
	}

	public void setProfile(String profile) {
		this.profile = profile;
	}

	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public void setCmwhen(String cmwhen) {
		this.cmwhen = cmwhen;
	}

	public int getRoses() {
		return roses;
	}

	public void setRoses(int roses) {
		this.roses = roses;
	}

	public int getEmails() {
		return emails;
	}

	public void setEmails(byte emails) {
		this.emails = emails;
	}

	public int getSilence() {
		return silence;
	}

	public int getFaSort() {
		return faSort;
	}

	public void setFaSort(byte faSort) {
		this.faSort = faSort;
	}

	public void setSilence(byte silence) {
		this.silence = silence;
	}

	public int getDreamsperre() {
		return dreamsperre;
	}

	public void setDreamsperre(byte dreamsperre) {
		this.dreamsperre = dreamsperre;
	}

	public int getPhotoVerify() {
		return photoVerify;
	}

	public void setPhotoVerify(byte photoVerify) {
		this.photoVerify = photoVerify;
	}

	public String getIgnoredNicks() {
		return ignoredNicks;
	}

	public void setIgnoredNicks(String ignoredNicks) {
		this.ignoredNicks = ignoredNicks;
	}

	public boolean checkIgnored(String nick) {
		return ignoredNicks.contains(String.format("|%s|", nick));
	}

	public void addIgnoredNick(String nick) {
		ignoredNicks = String.format("%s|%s|", ignoredNicks, nick);
	}

	public void removeIgnoredNick(String nick) {
		ignoredNicks = ignoredNicks.replace(String.format("|%s|", nick), "");
	}

	public int getStarlitesperre() {
		return starlitesperre;
	}

	public void setStarlitesperre(byte starlitesperre) {
		this.starlitesperre = starlitesperre;
	}

	public int getFriendssperre() {
		return friendssperre;
	}

	public void setFriendssperre(byte friendssperre) {
		this.friendssperre = friendssperre;
	}

	public int getKissed() {
		return kissed;
	}

	public void setKissed(byte kissed) {
		this.kissed = kissed;
	}

	public int getRosesSend() {
		return rosesSend;
	}

	public void setAwayReason(String awayReason) {
		this.awayReason = awayReason;
	}

	public String getAwayReason() {
		return awayReason;
	}

	public void setLotto(int lotto) {
		this.lotto = lotto;
	}

	public String getSpitznamen() {
		return spitznamen;
	}

	public void setSpitznamen(String spitznamen) {
		this.spitznamen = spitznamen;
	}

	public int getImmunsperre() {
		return immunsperre;
	}

	public void setImmunsperre(byte immunsperre) {
		this.immunsperre = immunsperre;
	}

	public int getLotto() {
		return lotto;
	}


	public void setRosesSend(byte rosesSend) {
		this.rosesSend = rosesSend;
	}

	private boolean away;

        
        
        private Client kdice_user;
        private int kdice_id;
        private int kdice_count;
        private String kdice_dice;
        
        
	public Client(Socket socket) {
		channels = new ArrayList<Channel>();
		this.socket = socket;

		if (socket == null) {
			return;
		}

		try {
			out = socket.getOutputStream();
		} catch (IOException e) {
		}
	}

	public List<Pair<String, Integer>> getIcons() {
		return icons;
	}

	private void addIcon(String icon, int size) {
		Pair<String, Integer> pair = new Pair<String, Integer>(icon, size);
		icons.add(pair);

		for (Channel channel : getChannels()) {
			for (Client target : channel.getClients()) {
				target.send(PacketCreator.addIcon(channel.getName(), name, pair));
			}
		}
	}

	private void removeIcon(String icon) {
		for (Pair<String, Integer> pair : icons) {
			if (pair.getLeft().equals(icon)) {
				icons.remove(pair);
				break;
			}
		}

		for (Channel channel : getChannels()) {
			String remove = PacketCreator.removeIcon(channel.getName(), name,
					icon);

			for (Client target : channel.getClients()) {
				target.send(remove);
			}
		}
	}

	public String getLike() {
		return like;
	}

	public void setLike(String like) {
		this.like = like;
	}

	public String getSchuetzlinge() {
		return schuetzlinge;
	}

	public void setSchuetzlinge(String schuetzlinge) {
		this.schuetzlinge = schuetzlinge;
	}

	public String getBirthday() {
		return birthday;
	}

	public void setBirthday(String birthday) {
		this.birthday = birthday;
	}

	public String getStammiwhen() {
		return stammiwhen;
	}

	public void setStammiwhen(String stammiwhen) {
		this.stammiwhen = stammiwhen;
	}

	public String getCmwhen() {
		return cmwhen;
	}

	public int getCmutes() {
		return cmutes;
	}

	public int getFlames() {
		return flames;
	}

	public void setFlames(int flames) {
		this.flames = flames;
	}

	public void setCmutes(int cmutes) {
		this.cmutes = cmutes;
	}

	public int getMutes() {
		return mutes;
	}

	public int getSexysperre() {
		return sexysperre;
	}

	public long getSpielsperre() {
		return spielsperre;
	}

	public void setSpielsperre(long spielsperre) {
		this.spielsperre = spielsperre;
	}

	public void setSexysperre(byte sexysperre) {
		this.sexysperre = sexysperre;
	}

	public String getPhoto() {
		return photo;
	}

	public void setPhoto(String photo) {
		this.photo = photo;
	}

	public void setMutes(int mutes) {
		this.mutes = mutes;
	}

	public int getCls() {
		return cls;
	}

	public String getQuizrang() {
		return quizrang;
	}

	public void setQuizrang(String quizrang) {
		this.quizrang = quizrang;
	}

	public void setCls(int cls) {
		this.cls = cls;
	}

	public int getJumpopunkte() {
		return jumpopunkte;
	}
	
	public int getForumCon() {
		return forumCon;
	}

	public void increaseJumpoPoints(float jumpoPoints) {
		this.jumpopunkte += jumpoPoints;
	}

	public void deseaseJumpoPoints(float jumpoPoints) {
		this.jumpopunkte -= jumpoPoints;
	}
	
	public void setHol(int hol) {
		this.hol = hol;
	}

	public int getSearchAgeFrom() {
		return searchAgeFrom;
	}

	public int getLCSperre() {
		return lcsperre;
	}

	public int getZeichen() {
		return zeichen;
	}

	public void setZeichen(int zeichen) {
		this.zeichen = zeichen;
	}

	public String getRegisterIP() {
		return registerIP;
	}

	public int getNewssperre() {
		return newssperre;
	}

	public void setNewssperre(byte newssperre) {
		this.newssperre = newssperre;
	}

	public int getShowEffects() {
		return showEffects;
	}

	public String getLastChannel() {
		return lastChannel;
	}

	public void setLastChannel(String lastChannel) {
		this.lastChannel = lastChannel;
	}

	public void setShowEffects(byte showEffects) {
		this.showEffects = showEffects;
	}

	public void setLCSperre(byte lcsperre) {
		this.lcsperre = lcsperre;
	}

	public String getLC() {
		return lc;
	}

	public void setLC(String lc) {
		this.lc = lc;
	}

	public String getVergeben() {
		return vergeben;
	}

	public String getDream() {
		return dream;
	}

	public void setDream(String dream) {
		this.dream = dream;
	}

	public int getAdmincallFirst() {
		return admincallFirst;
	}

	public void increaseAdmincallFirst() {
		this.admincallFirst += 1;
	}

	public int getAdmincallSecond() {
		return admincallSecond;
	}

	public void increaseAdmincallSecond() {
		this.admincallSecond += 1;
	}

	public int getAdmincallThird() {
		return admincallThird;
	}

	public void increaseAdmincallThird() {
		this.admincallThird += 1;
	}

	public String getFriends() {
		return friends;
	}

	public void setFriends(String friends) {
		this.friends = friends;
	}

	public void setVergeben(String vergeben) {
		this.vergeben = vergeben;
	}

	public int getSearchAgeUntil() {
		return searchAgeUntil;
	}

	public String getSearchGender() {
		return searchGender;
	}

	public String getSearchMotiv() {
		return searchMotiv;
	}

	public String getSearchEntfernung() {
		return searchEntfernung;
	}

	public void setSearchEntfernung(String searchEntfernung) {
		this.searchEntfernung = searchEntfernung;
	}
	
	public int getStammiMonths() {
		if(!stammiwhen.isEmpty()) {
			return CommandParser.countChars(stammiwhen, '|')+1;
		}
		
		return 0;
	}

	public void setSearchAgeFrom(byte searchAgeFrom) {
		this.searchAgeFrom = searchAgeFrom;
	}

	public int getErhalten() {
		return erhalten;
	}

	public void setErhalten(int erhalten) {
		this.erhalten = erhalten;
	}

	public int getHol() {
		return hol;
	}

	public void increaseHol(int hol) {
		this.hol += hol;
	}

	public int getVerschenkt() {
		return verschenkt;
	}

	public void setVerschenkt(int verschenkt) {
		this.verschenkt = verschenkt;
	}

	public void setSearchAgeUntil(byte searchAgeUntil) {
		this.searchAgeUntil = searchAgeUntil;
	}

	public void setSearchMotiv(String searchMotiv) {
		this.searchMotiv = searchMotiv;
	}

	public void setSearchGender(String searchGender) {
		this.searchGender = searchGender;
	}

	public String getName() {
		return name;
	}

	public int getEffect() {
		return effect;
	}

	public void setEffect(byte effect) {
		this.effect = effect;
	}

	public int getShowEmail() {
		return showEmail;
	}

	public void setShowEmail(byte showEmail) {
		this.showEmail = showEmail;
	}

	public int getShowBirthday() {
		return showBirthday;
	}

	public void setShowBirthday(byte showBirthday) {
		this.showBirthday = showBirthday;
	}

	public int getShowZodiac() {
		return showZodiac;
	}

	public void setShowZodiac(byte showZodiac) {
		this.showZodiac = showZodiac;
	}

	public int getSearchActivate() {
		return searchActivate;
	}

	public void setSearchActivate(byte searchActivate) {
		this.searchActivate = searchActivate;
	}

	public String getSignatur() {
		return signatur;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public void setSignatur(String signatur) {
		this.signatur = signatur;
	}

	public void increaseWordMixPoints(float wordmixPoints) {
		this.wordmixPoints += wordmixPoints;
	}

	public float getWordMixPoints() {
		return wordmixPoints;
	}

	public String getReadme() {
		return readme;
	}

	public int getMask() {
		return mask;
	}

	public void setMask(byte mask) {
		this.mask = mask;
	}

	public int getMentorPoints() {
		if (getRank() > 2) {
			return mentorPoints + 400;
		}

		return mentorPoints;
	}

	public void increaseMentorPoints(int mentorPoints) {
		this.mentorPoints += mentorPoints;
	}

	public void setReadme(String readme) {
		this.readme = readme;
	}

	public int getID() {
		return id;
	}

	public long getLastOnline() {
		return lastOnline;
	}

	public void setLastOnline(long lastOnline) {
		this.lastOnline = lastOnline;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public byte getRank() {
		return rank;
	}

	public void setRank(byte rank) {
		this.rank = rank;
	}

	public String getRankLabel(byte rank) {
		if (rank == 0) {
			return "Mitglied";
		} else if (rank == 1) {
			return "Familymitglied";
		} else if (rank == 2) {
			return "Stammi";
		} else if (rank == 3) {
			return "Ehrenmitglied";
		} else if (rank == 4) {
			return "Ehrenmitglied";
		} else if (rank == 5) {
			return "inoffizieller Admin";
		} else if (rank == 6 || rank == 7) {
			return "Admin";
		}

		return "Sysadmin";
	}

	public int getAge() {
		return age;
	}

	public String getRealName() {
		return realname;
	}

	public String getStadt() {
		return stadt;
	}

	public String getLand() {
		return land;
	}

	public String getHobbys() {
		return hobbys;
	}

	public String getJob() {
		return job;
	}

	public String getMotto() {
		return motto;
	}

	public void setRealName(String realname) {
		this.realname = realname;
	}

	public void setAge(byte age) {
		this.age = age;
	}

	public void setGender(byte gender) {
		this.gender = gender;
	}

	public void setStadt(String stadt) {
		this.stadt = stadt;
	}

	public void setLand(String land) {
		this.land = land;
	}

	public void setHobbys(String hobbys) {
		this.hobbys = hobbys;
	}

	public void setJob(String job) {
		this.job = job;
	}

	public void setMotto(String motto) {
		this.motto = motto;
	}

	public byte getGender() {
		return gender;
	}

	public int getSmileyCount() {
		return 3;
	}

	public int getKisses() {
		return kisses;
	}

	public void increaseKisses() {
		kisses++;
	}

	public long getTimeOut() {
		return timeOut;
	}

	public void setTimeOut(long timeOut) {
		this.timeOut = timeOut;
	}

	public boolean checkTeam(String team) {
		return teams.toLowerCase().contains(
				String.format("|%s~", team.toLowerCase()));
	}

	public boolean checkTeam(String team, int rank) {
		return teams.toLowerCase().contains(
				String.format("|%s~%s|", team.toLowerCase(), rank));
	}

	public boolean checkTeamLeader(String team) {
		return teams.toLowerCase().contains(
				String.format("|%s~1|", team.toLowerCase()));
	}


	public String getLastOnlineDate() {
		return Server.get().timeStampToDate(lastOnline);
	}

	public String getLastOnlineTime() {
		return Server.get().timeStampToTime(lastOnline);
	}

	public String getLastOnlineChannel() {
		return lastOnlineChannel;
	}

	public void setLastOnlineChannel(String lastOnlineChannel) {
		this.lastOnlineChannel = lastOnlineChannel;
	}

	public void increaseKnuddels(float knuddels) {
		this.knuddels += knuddels;
		Server.get().increaseAllKnuddels(knuddels);
	}

	public void deseaseKnuddels(int knuddels) {
		this.knuddels -= knuddels;
		Server.get().deseaseAllKnuddels(knuddels);
	}

	public int getTimeDay() {
		return timeDay
				+ (int) ((System.currentTimeMillis() - loginTimestamp) / 1000);
	}

	public int getTimeMonth() {
		return timeMonth
				+ (int) ((System.currentTimeMillis() - loginTimestamp) / 1000);
	}

	public int getOnlineTime() {
		return onlineTime
				+ (int) ((System.currentTimeMillis() - loginTimestamp) / 1000);
	}

	public int getAdminTime() {
		return adminTime
				+ (int) ((System.currentTimeMillis() - loginTimestamp) / 1000);
	}

	public String getLoginTime() {
		int bla = (int) ((System.currentTimeMillis() - loginTimestamp) / 1000 / 60);
		String what = "";

		if (bla < 1) {
			what = "gerade eben";
		} else {
			what = bla == 1 ? "einer Minute" : String.format("%s Minuten", bla);
		}

		return what;
	}

	public String getRegistrationDate() {
		return registrationDate;
	}

	public String getRegistrationTime() {
		return registrationTime;
	}

	public String getGenderLabel() {
		if (gender == 1) {
			return "Er";
		}

		if (gender == 2) {
			return "Sie";
		}

		return name;
	}

	public String getIPAddress() {
		return ipAddress;
	}

	public boolean isAway() {
		return away;
	}

	public void setAway(boolean away) {
		this.away = away;

		if (away) {
			if (rank > 7) {
				addIcon("pics/icon_away_ani_new.gif", 18);
			} else {
				addIcon("pics/away.png", 20);
			}
		} else {
			if (rank > 7) {
				removeIcon("pics/icon_away_ani_new.gif");
			} else {
				removeIcon("pics/away.png");
			}
		}
	}

        public int getDiceID() {
return kdice_id;
}

public String getDice() {
return kdice_dice;
}

public Client getDiceUser() {
return kdice_user;
}

public int getDiceCount() {
return kdice_count;
}

public void setDiceUser(Client user, int count, String dice) {
kdice_user = user;
kdice_id = IntegerUtil.rand(100000, 999999);
kdice_count = count;
kdice_dice = dice;
}

public void increaseKnuddels(int num) {
knuddels += num;
}

public void decreaseKnuddels(int num) {
knuddels -= num;
} 
        
        
        
	public boolean checkSpam(boolean kick, Channel channel) {
		long now = System.currentTimeMillis();

		if (rank < 8) {
			if (lastAction > now - channel.butlerMute()) {
				spam++;

				if (kick) {
					if (spam == 5) {
						disconnect();
					}
				} else {
					if (!Server.get().checkCcm(name, channel, 3)) {
						if (spam == 4 || spam == 8) {
							sendButlerMessage(channel.getName(),
									"Bitte _NICHT spammen_ und fluten.");
							increaseWarnings();
							return true;
						}

						if (spam == 10 || warnings == 3) {
							Long time = System.currentTimeMillis() / 1000;
							sendButlerMessage(
									channel.getName(),
									String.format(
											"Du wurdest soeben von °>_h%s|/serverpp \"|/w \"<° im Channel %s ge_°BB>mutet|/h mute<r°_.",
											Server.get().getButler().getName(),
											channel.getName()));
							channel.setMutes(String.format("%s|%s|",
									channel.getMutes(), name));

							if (channel.isVisible()) {
								setComment(time, channel.getName(), "Mute!",
										Server.get().getButler().getName(),
										"Spamming");
							}

							setWarnings((byte)0);

							return true;
						}
					}
				}
			} else {
				spam -= (now - lastAction) / channel.butlerMute();

				if (spam < 0) {
					spam = 0;
				}
			}
		}

		lastAction = now;
		return false;
	}

	public void login(String nickname) throws SQLException {
		if (name != null && !name.equals(nickname)) {
			logout("Ausgeloggt");
		}

		synchronized (channels) {
			if (channels.isEmpty()) {
				Client client = Server.get().getClient(nickname);

				if (client != null) {
					client.disconnect();
				}

				loadStats(nickname);
			}
		}
	}

	public void logout(String message) {
		synchronized (channels) {
			if (!channels.isEmpty()) { // is logged in
				for (Channel channel : channels) {
					channel.leave(this);

					if (message != null) {
						send(PacketCreator.kick(channel.getName(), message));
					}
				}

				saveStats();
				channels.clear();
				Server.get().removeClient(name);
				sendHello();
				setTimeOut(0);
				Logger.handle(null, String.format("%s logged out", name));
			}
		}
	}

	public Channel getChannel() {
		if (name.equals(Server.get().getButler().getName())) {
			return null;
		}

		synchronized (channels) {
			return channels.get(channels.size() - 1);
		}
	}

	public List<Channel> getChannels() {
		synchronized (channels) {
			return channels;
		}
	}

	public void joinChannel(Channel channel) {
		synchronized (channels) {
			if (channels.isEmpty()) { // logged in
				Server.get().addClient(this);
			}

			channels.add(channel);
		}
	}

	public void leaveChannel(Channel channel) {
		synchronized (channels) {
			channels.remove(channel);

			if (channels.isEmpty()) { // logged out
				setLastOnlineChannel(channel.getName());
				saveStats();
				Server.get().removeClient(name);
				sendHello();
				setTimeOut(0);
				Logger.handle(null, String.format("%s logged out", name));
			}
		}
	}

	public void setComment(long time, String channel, String zusatz,
			String von, String text) {
		Client v = Server.get().getClient(von);
		Client t = Server.get().getClient(name);
		boolean online = true;
		if (t == null) {
			online = false;
		}
		StringBuilder cm = new StringBuilder();

		if (v == null) {
			v = new Client(null);
			v.loadStats(von);
		}

		text = KCodeParser.parse(v, text, 5, 10, 20);
		text = Server.get().parseSmileys(v, text);

		cm.append("_°>_h");
		cm.append(von.replace("<", "\\<"));
		cm.append("|/serverpp \"|/w \"<°_");
		if (channel != null) {
			cm.append(" im °>_h");
			cm.append(channel).append("|/go \"|/go +\"<°");
		}
		cm.append(": ");
		if (zusatz != null) {
			cm.append("_\"").append(zusatz).append("_\" ");
		}
		cm.append(text).append(" (").append(Server.get().timeStampToDate(time))
				.append(" ").append(Server.get().timeStampToTime(time))
				.append(")#");

		if (channel == null) {
			if (online) {
				setComments(String.format("%s%s", getComments(), cm.toString()));
			} else {
				Server.get()
						.query(String
								.format("UPDATE accounts SET comments = '%s%s' WHERE name = '%s'",
										getComments(), cm.toString(), name));
			}
		} else {
			if (online) {
				setCmcomments(String.format("%s%s", getCmcomments(),
						cm.toString()));
			} else {
				Server.get()
						.query(String
								.format("UPDATE accounts SET cmComments = '%s%s' WHERE name = '%s'",
										getCmcomments(), cm.toString(), name));
			}
		}

	}

	public void loadStats(String name) {
		PoolConnection pcon = ConnectionPool.getConnection();
		Statement ps = null;

		try {
			Connection con = pcon.connect();
			ps = con.createStatement();
			ResultSet rs = ps
					.executeQuery(String
							.format("SELECT `authActive`,`authPassword`,`user_posts`,`aktuTut`,`tutOpen`,`tutAktiv`,`thiefgame`,`messageSound`,`knuddelscentLock`,`knuddelscentLevel`,`emailVerify`,`emails`,`missed`, `like`,`holdhands`,`element`,`smileys`,`readmeeffects`,`zusammen`,`aktuTut`,`newPhotoComment`,`host`,`snp`,`agePlus`,`kissed`,`color`,`sun`,`sunLock`,`weckMessage`,`agent`,`butterflysperre`,`bazookasperre`,`flyingbedsperre`,`winksperre`,`immunsperre`,`healsperre`,`heartMessage`,`kontoKnuddels`,`kontoPassword`,`mpFriendlist`,`mpChat`,`belohnen`,`sperrevon`,`sperre`,`disable`,`deletenick`,`sperreinfo`,`spielsperre`,`heart`,`knuddels`,`timeDay`,`timeMonth`,`photo`,`lcmonths`,`schuetzlinge`,`cmwhen`,`stammiwhen`,`hol`,`analysedatasperre`,`kicks`,`locks`, `notrufsperre`,`adminTime`, `showEffects`,`sexysperre`,`faSort`, `admincallFirst`, `admincallSecond`, `admincallThird`, `erhalten`, `verschenkt`, `aufrufe`, `photoVerify`, `name`, `rank`, `gender`, `kisses`, `comments`, `cmcomments`, `plz`, `plzCountry`, `starsFrom`, `scrollspeed`, `spitznamen`, `starsTo`, `kissall`, `wahlsperre`, `heartLock`, `friendlist`, `password`, `profile`, `onlineTime`, `career`, `mentor`, `newssperre`, `age`, `mentorPoints`, `mask`, `teams`, `grippestatus`, `lotto`, `ig`, `id`, `cls`, `roses`, `rosesSend`, `cmutes`, `mutes`, `realname`, `friends`, `dream`, `stadt`, `desc`, `birthday`, `wordmixPoints`, `land`, `signature`, `hobbys`, `ipAddress`, `registerIP`, `job`, `lcsperre`, `zeichen`, `dreamsperre`, `friendssperre`, `starlitesperre`, `silence`, `lc`, `effect`, `motto`, `readme`, `showEmail`, `jumpopunkte`, `tutOpen`, `searchGender`, `searchAgeFrom`, `searchAgeUntil`, `searchEntfernung`, `flames`, `searchMotiv`, `showBirthday`, `searchActivate`, `showZodiac`, `vergeben`, `email`, `verify`, `lastOnlineChannel`, `lastOnline`, `date`, `registration` FROM `accounts` WHERE `name` = '%s'",
									name));

			if (rs.next()) {
				this.name = rs.getString("name");
				snp = rs.getByte("snp");
				authActive = rs.getByte("authActive");
				authPassword = rs.getString("authPassword");
				forumCon = rs.getInt("user_posts");
				emailVerify = rs.getByte("emailVerify");
				holdhands = rs.getString("holdhands");
				smileys = rs.getString("smileys");
				element = rs.getInt("element");
				readmeEffects = rs.getByte("readmeeffects");
				newPhotoComment = rs.getByte("newPhotoComment");
				zusammen = rs.getString("zusammen");
				like = rs.getString("like");
				rank = rs.getByte("rank");
				agePlus = rs.getByte("agePlus");
				kissed = rs.getByte("kissed");
				weckMessage = rs.getByte("weckMessage");
				sun = rs.getByte("sun");
				sunLock = rs.getByte("sunLock");
				icons = new ArrayList<Pair<String, Integer>>();
				gender = rs.getByte("gender");
				bazookasperre = rs.getByte("bazookasperre");
				missed = rs.getString("missed");
				agent = rs.getString("agent");
				butterflysperre = rs.getByte("butterflysperre");
				immunsperre = rs.getByte("immunsperre");
				flyingbedsperre = rs.getByte("flyingbedsperre");
				winksperre = rs.getByte("winksperre");
				photoVerify = rs.getByte("photoVerify");
				heartMessage = rs.getByte("heartMessage");
				grippestatus = rs.getByte("grippestatus");
				onlineTime = rs.getInt("onlineTime");
				adminTime = rs.getInt("adminTime");
				heart = rs.getString("heart");
				belohnen = rs.getByte("belohnen");
				timeMonth = rs.getInt("timeMonth");
				timeDay = rs.getInt("timeDay");
				photo = rs.getString("photo");
				kontoPassword = rs.getString("kontoPassword");
				kontoKnuddels = rs.getInt("kontoKnuddels");
				mpChat = rs.getByte("mpChat");
				mpFriendlist = rs.getByte("mpFriendlist");
				knuddels = rs.getFloat("knuddels");
				color = rs.getString("color");
				knuddelscentLevel = rs.getByte("knuddelscentLevel");
				knuddelscentLock = rs.getByte("knuddelscentLock");
				messageSound = rs.getByte("messageSound");
				thiefGame = rs.getInt("thiefgame");
				
				if (gender == 1) {
					addIcon("pics/male.png", 16);
				} else if (gender == 2) {
					addIcon("pics/female.png", 14);
				}

				if (photoVerify == 1) {
					addIcon("pics/fv_checked.png", 18);
				}

				if (grippestatus > 0) {
					addIcon("pics/nose.gif", 18);
				}

				if (Server.sexy.contains(name)) {
					addIcon("pics/sexy.gif", 24);
				}

				kisses = rs.getInt("kisses");
				sexysperre = rs.getByte("sexysperre");
				comments = rs.getString("comments");
				cmwhen = rs.getString("cmwhen");
				sperrevon = rs.getString("sperrevon");
				sperre = rs.getLong("sperre");
                                disable = rs.getLong("disable");
                                deletenick = rs.getLong("deletenick");
				sperreinfo = rs.getString("sperreinfo");
				stammiwhen = rs.getString("stammiwhen");
				cmcomments = rs.getString("cmcomments");
				lcmonths = rs.getByte("lcmonths");
				hol = rs.getInt("hol");
				plz = rs.getString("plz");
				plzLand = rs.getString("plzCountry");
				starsFrom = rs.getString("starsFrom");
				scrollspeed = rs.getInt("scrollspeed");
				admincallFirst = rs.getInt("admincallFirst");
				admincallSecond = rs.getInt("admincallSecond");
				admincallThird = rs.getInt("admincallThird");
				emails = rs.getByte("emails");
				erhalten = rs.getInt("erhalten");
				verschenkt = rs.getInt("verschenkt");
				kicks = rs.getInt("kicks");
                                locks = rs.getInt("locks");
				notrufsperre = rs.getLong("notrufsperre");
				spitznamen = rs.getString("spitznamen");
				starsTo = rs.getString("starsTo");
				showEffects = rs.getByte("showEffects");
				kissall = rs.getByte("kissall");
				wahlsperre = rs.getLong("wahlsperre");
				heartsperre = rs.getByte("heartLock");
				verify = rs.getByte("verify");
				password = rs.getString("password");
				friendlist = rs.getString("friendlist");
				faSort = rs.getByte("faSort");
				profile = rs.getString("profile");
				career = rs.getString("career");
				mentor = rs.getString("mentor");
				newssperre = rs.getByte("newssperre");
				loginTimestamp = System.currentTimeMillis();
				age = rs.getByte("age");
				mentorPoints = rs.getInt("mentorPoints");
				spielsperre = rs.getLong("spielsperre");
				mask = rs.getByte("mask");
				teams = rs.getString("teams");
				lotto = rs.getInt("lotto");
				ignoredNicks = rs.getString("ig");
				id = rs.getInt("id");
				cls = rs.getInt("cls");
				roses = rs.getInt("roses");
				rosesSend = rs.getByte("rosesSend");
				cmutes = rs.getInt("cmutes");
				mutes = rs.getInt("mutes");
				realname = rs.getString("realname");
				friends = rs.getString("friends");
				dream = rs.getString("dream");
				stadt = rs.getString("stadt");
				desc = rs.getString("desc");
				birthday = rs.getString("birthday");
				wordmixPoints = rs.getFloat("wordmixpoints");
				aufrufe = rs.getInt("aufrufe");
				land = rs.getString("land");
				signatur = rs.getString("signature");
				hobbys = rs.getString("hobbys");
				job = rs.getString("job");
				registerIP = rs.getString("registerIP");
				zeichen = rs.getInt("zeichen");
				lcsperre = rs.getByte("lcsperre");
				friendssperre = rs.getByte("friendssperre");
				dreamsperre = rs.getByte("dreamsperre");
				silence = rs.getByte("silence");
				starlitesperre = rs.getByte("starlitesperre");
				lc = rs.getString("lc");
				motto = rs.getString("motto");
				healsperre = rs.getByte("healsperre");
				effect = rs.getByte("effect");
				readme = rs.getString("readme");
				showEmail = rs.getByte("showEmail");
				analysedatasperre = rs.getByte("analysedatasperre");
				jumpopunkte = rs.getInt("jumpopunkte");
				searchGender = rs.getString("searchGender");
				searchEntfernung = rs.getString("searchEntfernung");
				flames = rs.getInt("flames");
				searchAgeFrom = rs.getByte("searchAgeFrom");
				searchAgeUntil = rs.getByte("searchAgeUntil");
				searchMotiv = rs.getString("searchMotiv");
				showBirthday = rs.getByte("showBirthday");
				searchActivate = rs.getByte("searchActivate");
				vergeben = rs.getString("vergeben");
				schuetzlinge = rs.getString("schuetzlinge");
				showZodiac = rs.getByte("showZodiac");
				email = rs.getString("email");
				lastOnlineChannel = rs.getString("lastOnlineChannel");
				lastOnline = rs.getLong("lastOnline");
				date = rs.getString("date");
				long registration = rs.getLong("registration");
				registrationDate = Server.get().timeStampToDate(registration);
				registrationTime = Server.get().timeStampToTime(registration);
				host = rs.getString("host");
				tutOpen = rs.getByte("tutOpen");
				tutAktiv = rs.getByte("tutAktiv");
				aktuTut = rs.getByte("aktuTut");

				if (socket == null) {
					ipAddress = rs.getString("ipAddress");
					host = rs.getString("host");
				} else {
					ipAddress = socket.getInetAddress().getHostAddress();
					host = socket.getInetAddress().getHostName();
				}

				away = false;
				spam = 0;
				lastAction = 0;
			}
			rs.close();
			rs = ps.executeQuery(String.format(
					"select text,time from readmes where name='%s'",
					id));
			while (rs.next()) {
				String text = rs.getString("text");
				long time = rs.getLong("time");
				
				readmes.put(time, text);
			}
			rs.close();
			rs = ps.executeQuery(String.format(
					"SELECT `time`,`an`,`betreff`,`text` FROM `messages` WHERE `von` = '%s' order by time desc limit 5",
					name));
			while (rs.next()) {
				long time = rs.getLong("time");
				String an = rs.getString("an");
				String betreff = rs.getString("betreff");
				String text = rs.getString("text");
				String[] a = new String[]{String.valueOf(time),an,betreff,text};
				
				if(!sentMessages.contains(a)) {
					sentMessages.add(a);
				}
			}
			rs.close();
			rs = ps.executeQuery(String.format(
					"SELECT `time`,`von`,`betreff`,`text` FROM `messages` WHERE `gelesen` = '1' and `an` = '%s' order by time desc limit 20",
					name));
			while (rs.next()) {
				long time = rs.getLong("time");
				String von = rs.getString("von");
				String betreff = rs.getString("betreff");
				String text = rs.getString("text");
				String[] a = new String[]{String.valueOf(time),von,betreff,text};
				
				if(!oldMessages.contains(a)) {
					oldMessages.add(a);
				}
			}
			rs.close();
			rs = ps.executeQuery(String.format(
					"SELECT `time`,`von`,`betreff`,`text` FROM `messages` WHERE `gelesen` = '0' and `an` = '%s'",
					name));
			while (rs.next()) {
				long time = rs.getLong("time");
				String von = rs.getString("von");
				String betreff = rs.getString("betreff");
				String text = rs.getString("text");
				String[] a = new String[]{String.valueOf(time),von,betreff,text};
				
				if(!newMessages.contains(a)) {
					newMessages.add(a);
				}
			}
			rs.close();
			rs = ps.executeQuery(String.format(
					"SELECT `id`, `verstoss`, `abgesetzt` FROM `admincalls` where ergebnis='Notruf berechtigt' and beschuldigter='%s' order by abgesetzt",
					name));
			while (rs.next()) {
				long bla = rs.getLong("abgesetzt");
				admincalls.add(new String[] {rs.getString("verstoss"), rs.getString("id"), String.format("%s %s", Server.get().timeStampToDate(bla), Server.get().timeStampToTime(bla))});
			}
			rs.close();
			rs = ps.executeQuery(String.format(
					"SELECT `name` FROM `accounts` WHERE `heart`= '%s'",
					name));
			while (rs.next()) {
				String nick = rs.getString("name");
				
				if(!receivedHearts.contains(nick)) {
					receivedHearts.add(nick);
				}
			}
			rs.close();
			rs = ps.executeQuery(String.format(
					"SELECT `uhrzeit`, `ip` FROM `loginlist` where name = '%s' order by uhrzeit desc",
					name));
			while (rs.next()) {
				String[] x = new String[] {rs.getString("uhrzeit"), rs.getString("ip")};
				
				if(!logins.contains(x)) {
					logins.add(x);
				}
			}
			rs.close();
			rs = ps.executeQuery(String.format(
					"select von, uhrzeit, text from roses where an = '%s' and erhalten = 1 order by id desc limit 10",
					name));
			while (rs.next()) {
				String[] x = new String[] {rs.getString("von"), rs.getString("text"), rs.getString("uhrzeit")};
				
				if(!rosen.contains(x)) {
					rosen.add(x);
				}
			}
			rs.close();
			rs = ps.executeQuery(String.format(
					"SELECT von, text, id FROM `roses` where erhalten = 0 and an = '%s' order by id",
					name));
			while (rs.next()) {
				String[] x = new String[] {rs.getString("von"), rs.getString("text"), rs.getString("id")};
				
				if(!newRoses.contains(x)) {
					newRoses.add(x);
				}
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			if (ps != null) {
				try {
					ps.close();
				} catch (SQLException e) {
				}
			}

			pcon.close();
		}
	}

	public void saveStats() {
		long systemtime = System.currentTimeMillis() / 1000;

		PoolConnection pcon = ConnectionPool.getConnection();
		PreparedStatement ps = null;

		try {
			Connection con = pcon.connect();
			ps = con.prepareStatement("UPDATE `accounts` SET `kisses` = ?, `desc` = ?, `onlineTime` = ?, `ipAddress` = ?, `realname` = ?, `stadt` = ?, `land` = ?, `hobbys` = ?, `job` = ?, `motto` = ?, `age` = ?, `password` = ?, `gender` = ?, `readme` = ?, `lastOnline` = ?, `lastOnlineChannel` = ?, `wordmixPoints` = ?, `mask` = ?, `effect` = ?, `signature` = ?, `email` = ?, `showEmail` = ?, `showZodiac` = ?, `showBirthday` = ?, `searchActivate` = ?, `searchAgeUntil` = ?, `searchAgeFrom` = ?, `searchEntfernung` = ?, `searchMotiv` = ?, `searchGender` = ?, `vergeben` = ?, `birthday` = ?, `lcsperre` = ?, `lc` = ?, `zeichen` = ?, `cls` = ?, `cmutes` = ?, `mutes` = ?, `flames` = ?, `friends` = ?, `dream` = ?, `roses` = ?, `rosesSend` = ?, `lotto` = ?, `newssperre` = ?, `date` = ?, `career` = ?, `profile` = ?, `heartLock` = ?, `ig` = ?, `friendlist` = ?, `comments` = ?, `cmcomments` = ?, `plz` = ?, `plzCountry` = ?, `verify` = ?, `starsFrom` = ?, `starsTo` = ?, `snp` = ?, `teams` = ?, `scrollspeed` = ?, `wahlsperre` = ?, `silence` = ?, `dreamsperre` = ?, `friendssperre` = ?, `starlitesperre` = ?, `mentor` = ?, `kissall` = ?, `tutOpen` = ?, `jumpopunkte` = ?, `spitznamen` = ?, `aufrufe` = ?, `hol`=?, `admincallFirst` = ?, `admincallSecond` = ?, `admincallThird` = ?, `faSort` = ?,`zusammen` = ?,`sexysperre` = ?, `rank`=?, `showEffects`=?,`adminTime` = ?,`kicks` = ?,`notrufsperre` = ?,`analysedatasperre`=?,`schuetzlinge`=?,`lcmonths` =?,`tutAktiv`=?,`cmwhen`=?,`timeDay`=?,`timeMonth`=?,`knuddels`=?,`photo`=?,`spielsperre`=?,`sperre`=?,`sperreinfo`=?,`sperrevon`=?,`belohnen`=?,`mentorPoints`=?,`mpChat`=?,`mpFriendlist`=?,`kontoKnuddels`=?, `kontoPassword`=?,`heartMessage`=?,`healsperre`=?,`grippestatus`=?,`immunsperre`=?,`flyingbedsperre`=?,`winksperre`=?,`bazookasperre`=?,`butterflysperre`=?,`weckMessage`=?,`sun`=?,`sunLock`=?,`color` =?,`erhalten`=?,`verschenkt`=?,`kissed`=?,`agePlus`=?,`newPhotoComment`=?,`aktuTut`=?,`stammiwhen`=?,`readmeeffects`=?,`smileys`=?,`element`=?,`holdhands` = ?, `like` = ?,`missed`=?,`emails`=?,`emailVerify`=?,`knuddelscentLevel`=?,`knuddelscentLock`=?,`messageSound`=?,`thiefGame`=?,`photoVerify`=?,`disable`=?,`deletenick`=?,`locks`=?,`authPassword`=?,`authActive`=? WHERE `name` = ? LIMIT 1");
			ps.setInt(1, kisses);
			ps.setString(2, desc);
			ps.setInt(3, getOnlineTime());
			ps.setString(4, ipAddress);
			ps.setString(5, realname);
			ps.setString(6, stadt);
			ps.setString(7, land);
			ps.setString(8, hobbys);
			ps.setString(9, job);
			ps.setString(10, motto);
			ps.setInt(11, age);
			ps.setString(12, password);
			ps.setInt(13, gender);
			ps.setString(14, readme);
			ps.setLong(15, systemtime);
			ps.setString(16, lastOnlineChannel);
			ps.setFloat(17, wordmixPoints);
			ps.setInt(18, mask);
			ps.setInt(19, effect);
			ps.setString(20, signatur);
			ps.setString(21, email);
			ps.setInt(22, showEmail);
			ps.setInt(23, showZodiac);
			ps.setInt(24, showBirthday);
			ps.setInt(25, searchActivate);
			ps.setInt(26, searchAgeUntil);
			ps.setInt(27, searchAgeFrom);
			ps.setString(28, searchEntfernung);
			ps.setString(29, searchMotiv);
			ps.setString(30, searchGender);
			ps.setString(31, vergeben);
			ps.setString(32, birthday);
			ps.setInt(33, lcsperre);
			ps.setString(34, lc);
			ps.setInt(35, zeichen);
			ps.setInt(36, cls);
			ps.setInt(37, cmutes);
			ps.setInt(38, mutes);
			ps.setInt(39, flames);
			ps.setString(40, friends);
			ps.setString(41, dream);
			ps.setInt(42, roses);
			ps.setInt(43, rosesSend);
			ps.setInt(44, lotto);
			ps.setInt(45, newssperre);
			ps.setString(46, date);
			ps.setString(47, career);
			ps.setString(48, profile);
			ps.setInt(49, heartsperre);
			ps.setString(50, ignoredNicks);
			ps.setString(51, friendlist);
			ps.setString(52, comments);
			ps.setString(53, cmcomments);
			ps.setString(54, plz);
			ps.setString(55, plzLand);
			ps.setInt(56, verify);
			ps.setString(57, starsFrom);
			ps.setString(58, starsTo);
			ps.setInt(59, snp);
			ps.setString(60, teams);
			ps.setInt(61, scrollspeed);
			ps.setLong(62, wahlsperre);
			ps.setInt(63, silence);
			ps.setInt(64, dreamsperre);
			ps.setInt(65, friendssperre);
			ps.setInt(66, starlitesperre);
			ps.setString(67, mentor);
			ps.setInt(68, kissall);
			ps.setInt(69, tutOpen);
			ps.setInt(70, jumpopunkte);
			ps.setString(71, spitznamen);
			ps.setInt(72, aufrufe);
			ps.setInt(73, hol);
			ps.setInt(74, admincallFirst);
			ps.setInt(75, admincallSecond);
			ps.setInt(76, admincallThird);
			ps.setInt(77, faSort);
			ps.setString(78, zusammen);
			ps.setInt(79, sexysperre);
			ps.setByte(80, rank);
			ps.setInt(81, showEffects);
			ps.setInt(82, getAdminTime());
			ps.setInt(83, kicks);
			ps.setLong(84, notrufsperre);
			ps.setInt(85, analysedatasperre);
			ps.setString(86, schuetzlinge);
			ps.setInt(87, lcmonths);
			ps.setInt(88, tutAktiv);
			ps.setString(89, cmwhen);
			ps.setInt(90, getTimeDay());
			ps.setInt(91, getTimeMonth());
			ps.setFloat(92, knuddels);
			ps.setString(93, photo);
			ps.setLong(94, spielsperre);
			ps.setLong(95, sperre);
			ps.setString(96, sperreinfo);
			ps.setString(97, sperrevon);
			ps.setInt(98, belohnen);
			ps.setInt(99, mentorPoints);
			ps.setInt(100, mpChat);
			ps.setInt(101, mpFriendlist);
			ps.setInt(102, kontoKnuddels);
			ps.setString(103, kontoPassword);
			ps.setInt(104, heartMessage);
			ps.setInt(105, healsperre);
			ps.setInt(106, grippestatus);
			ps.setInt(107, immunsperre);
			ps.setInt(108, flyingbedsperre);
			ps.setInt(109, winksperre);
			ps.setInt(110, bazookasperre);
			ps.setInt(111, butterflysperre);
			ps.setInt(112, weckMessage);
			ps.setInt(113, sun);
			ps.setInt(114, sunLock);
			ps.setString(115, color);
			ps.setInt(116, erhalten);
			ps.setInt(117, verschenkt);
			ps.setInt(118, kissed);
			ps.setInt(119, agePlus);
			ps.setInt(120, newPhotoComment);
			ps.setInt(121, aktuTut);
			ps.setString(122, stammiwhen);
			ps.setInt(123, readmeEffects);
			ps.setString(124, smileys);
			ps.setInt(125, element);
			ps.setString(126, holdhands);
			ps.setString(127, like);
			ps.setString(128, missed);
			ps.setInt(129, emails);
			ps.setInt(130, emailVerify);
			ps.setInt(131, knuddelscentLevel);
			ps.setInt(132, knuddelscentLock);
			ps.setInt(133, messageSound);
			ps.setInt(134, thiefGame);
                        ps.setByte(135, photoVerify);
                        ps.setLong(136, disable);
                        ps.setLong(137, deletenick); 
                        ps.setInt(138, locks);
			ps.setString(139, authPassword);
			ps.setByte(140, authActive);
			ps.setString(141, name);
			ps.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			if (ps != null) {
				try {
					ps.close();
				} catch (SQLException e) {
				}
			}

			pcon.close();
		}

		if (holrunde != 0) {
			Server.get().newMessage(
							Server.get().getButler(),
							name,
							"High or Low",
							String.format(
									"Hallo %s,##da du dich ausgeloggt hast, wurde deine aktuelle High or Low Runde abgebrochen und nicht mehr gewertet.##Hochachtungsvoll,#James",
									name),  System.currentTimeMillis()/1000);
		}

		setLastChannel(null);
		setNewChannel(null);
		readmes.clear();
		logins.clear();
		newRoses.clear();
		rosen.clear();
		admincalls.clear();
		receivedHearts.clear();
		oldMessages.clear();
		sentMessages.clear();
		newMessages.clear();
	}

	public void sendHello() {
		Collection<Channel> channelList = Server.get().getChannels();
		send(PacketCreator
				.hello(((Channel) channelList.toArray()[0]).getName()));
		send(PacketCreator.channelList(channelList, getLoginCategory()));
	}

	public void sendPrivateMessage(List<Client> targets, String message,
			Channel channel, boolean fromGame) {
		if (!fromGame
				&& channel.getGame() != null
				&& !channel.getGame().parsePrivateMessage(targets, message,
						this)) {
			return;
		}
		
		message = KCodeParser.parse(this, message, 5, 10, 20);
		message = Server.get().parseSmileys(this, message);

		if (message.isEmpty()) {
			return;
		}

		StringBuilder recipients = new StringBuilder();

		for (Client target : targets) {
			recipients.append(target.getName());
			recipients.append(",");
		}

		String recipient = recipients.substring(0, recipients.length() - 1);

		if (!targets.contains(this)) {
			targets.add(this);
		}

		for (Client target : targets) {
			if (channel.getClients().contains(target)) {
				target.send(PacketCreator.privateMessage(name, recipient,
						channel.getName(), message, " "));
			} else {
				for (Channel ch : target.getChannels()) {
					target.send(PacketCreator.privateMessage(name, recipient,
							ch.getName(), message,
							channel.isVisible() ? channel.getName() : "?"));
				}
			}

			if (target.isAway()) {
				sendButlerMessage(channel.getName(), String.format(
						"%s ist gerade _/away_!%s",
						target.getName(),
						target.getAwayReason() == null ? "" : String.format(
								" (%s)", target.getAwayReason())));
			}
		}
	}

	public void sendButlerMessage(String channel, String message) {
		send(PacketCreator.privateMessage(Server.get().getButler().getName(),
				name, channel, message, " "));
	}

	public void send(String message) {
		if (socket != null && socket.isConnected()) {
			try {
				out.write(Protocol.encode(message.getBytes("UTF8")));
				// out.write(Protocol.encode(Huffman.encode(message)));
			} catch (Exception e) {
			}
		}
	}

	public void disconnect() {
		logout(null);

		if (socket != null && !socket.isClosed()) {
			try {
				socket.close();
			} catch (Exception e) {
			}
		}
	}
}
