//
// C++ Interface: server
//
// Description: 
//
//
// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2006
//
// Copyright: See COPYING file that comes with this distribution
//
//

#include <QMainWindow>
#include <QMap>
#include <QSignalMapper>

class QTcpServer;
class QTcpSocket;
class QLCDNumber;

class CServer:public QMainWindow
{
	Q_OBJECT
	public:
		CServer(int,QWidget*p=0);
		~CServer();
		
	private slots:
		void discon(int);
		void doread(int);
		void newcon();
		
	private:
		//server socket
		QTcpServer*serv;
		//client store
		int nextid;
		struct Client{
			QTcpSocket*sock;
			QString nick,buf;
		};
		QMap<int,Client>clients;
		//used to map client signals to the right client-id
		QSignalMapper disconmap,readmap;
		//main widget:
		QLCDNumber*disp;
		//used to process new data, returns true if there is more to do
		bool processClient(int);
		//used to process commands
		void processCommands(QString,int);
		//used to send a line to all clients
		void sendData(QString);
};
