+void Server::putRawLine(QString s) {
+ qDebug() << "SentRaw: " << s;
+ s += "\r\n";
+ socket.write(s.toAscii());
+}
+
+void Server::putCmd(QString cmd, QStringList params, QString prefix) {
+ QString m;
+ if(!prefix.isEmpty()) m += ":" + prefix + " ";
+ m += cmd.toUpper();
+ for(int i = 0; i < params.size() - 1; i++) {
+ m += " " + params[i];
+ }
+ if(!params.isEmpty()) m += " :" + params.last();
+ qDebug() << "SentCmd: " << m;
+ m += "\r\n";
+ socket.write(m.toAscii());
+}
+
+/** Handle a raw message string sent by the server. We try to find a suitable handler, otherwise we call a default handler. */
+void Server::handleServerMsg(QString msg) {
+ try {
+ if(msg.isEmpty()) {
+ qWarning() << "Received empty string from server!";
+ return;
+ }
+ // OK, first we split the raw message into its various parts...
+ QString prefix;
+ QString cmd;
+ QStringList params;
+ if(msg[0] == ':') {
+ msg.remove(0,1);
+ prefix = msg.section(' ', 0, 0);
+ msg = msg.section(' ', 1);
+ }
+ cmd = msg.section(' ', 0, 0).toUpper();
+ msg = msg.section(' ', 1);
+ QString left = msg.section(':', 0, 0);
+ QString trailing = msg.section(':', 1);
+ if(!left.isEmpty()) {
+ params << left.split(' ', QString::SkipEmptyParts);
+ }
+ if(!trailing.isEmpty()) {
+ params << trailing;
+ }
+ // Now we try to find a handler for this message. BTW, I do love the Trolltech guys ;-)
+ QString hname = cmd.toLower();
+ hname[0] = hname[0].toUpper();
+ hname = "handle" + hname + "FromServer";
+ if(!QMetaObject::invokeMethod(this, hname.toAscii(), Q_ARG(QString, prefix), Q_ARG(QStringList, params))) {
+ // Ok. Default handler it is.
+ defaultHandlerForServer(cmd, prefix, params);
+ }
+ } catch(Exception e) {
+ emit recvLine(e.msg());
+ }
+}
+
+void Server::defaultHandlerForServer(QString cmd, QString prefix, QStringList params) {
+ uint num = cmd.toUInt();
+ if(num) {
+ recvLine(cmd + " " + params.join(" "));
+ } else {
+ recvLine(QString("Unknown: ") + cmd + " " + params.join(" "));
+ }
+}
+
+void Server::handleUserMsg(QString usrMsg) {
+
+}
+
+/*