First sorta working network code added. We can connect to a server now and send/recv
[quassel.git] / network / messages.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005/06 by The Quassel Team                             *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #include "messages.h"
22 #include <QtDebug>
23
24 extern BuiltinCmd builtins[];
25
26 QHash<QString, CmdType> Message::cmdTypes;
27
28 Message::Message(QString _cmd, QStringList args) {
29   cmd = _cmd; qDebug() << "cmd: " << cmd;
30   params = args;
31 }
32
33 void Message::init() {
34   // Register builtin commands
35   for(int i = 0; ; i++) {
36     if(!builtins[i].handler) break;
37     CmdType c;
38     c.cmd = builtins[i].cmd.toLower();
39     c.cmdDescr = builtins[i].cmdDescr;
40     c.args = builtins[i].args;
41     c.argsDescr = builtins[i].argsDescr;
42     c.handler = builtins[i].handler;
43     cmdTypes.insert(c.cmd, c);
44   }
45
46 }
47
48 cmdhandler Message::getCmdHandler() {
49   CmdType c = cmdTypes[cmd];
50   if(c.handler) return c.handler;
51   qDebug() << "No handler defined for " << cmd << "!";
52   return 0;
53 }
54
55 /*
56 void Message::parseParams(QString str) {
57   QString left = str.section(':', 0, 0);
58   QString trailing = str.section(':', 1);
59   if(left.size()) {
60     params << left.split(' ', QString::SkipEmptyParts);
61   }
62   if(trailing.size()) {
63     params << trailing;
64   }
65   qDebug() << params;
66
67 }
68 */
69 void Message::test1(QStringList foo) { qDebug() << "Test 1! " << cmd; };
70
71 void Message::test2(QStringList bar) { qDebug() << "Test 2!"; };