QTfrontend/netclient.cpp
author unc0rr
Fri, 23 Dec 2005 23:14:31 +0000
changeset 29 9311259d5242
parent 28 59f7db859b8a
child 31 99888245a4e8
permissions -rw-r--r--
More work on net game, still far from complete
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
     1
/*
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
     2
 * Hedgewars, a worms-like game
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
     3
 * Copyright (c) 2005 Andrey Korotaev <unC0Rr@gmail.com>
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
     4
 *
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
     5
 * Distributed under the terms of the BSD-modified licence:
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
     6
 *
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
     7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
     8
 * of this software and associated documentation files (the "Software"), to deal
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
     9
 * with the Software without restriction, including without limitation the
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    10
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    11
 * sell copies of the Software, and to permit persons to whom the Software is
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    12
 * furnished to do so, subject to the following conditions:
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    13
 *
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    14
 * 1. Redistributions of source code must retain the above copyright notice,
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    15
 *    this list of conditions and the following disclaimer.
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    16
 * 2. Redistributions in binary form must reproduce the above copyright notice,
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    17
 *    this list of conditions and the following disclaimer in the documentation
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    18
 *    and/or other materials provided with the distribution.
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    19
 * 3. The name of the author may not be used to endorse or promote products
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    20
 *    derived from this software without specific prior written permission.
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    21
 *
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    22
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    23
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    24
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    25
 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    26
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    27
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    28
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    29
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    30
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    31
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    32
 */
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    33
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    34
#include <QMessageBox>
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    35
#include "netclient.h"
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    36
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    37
HWNet::HWNet()
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    38
	: QObject()
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    39
{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    40
	state = nsDisconnected;
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    41
	IRCmsg_cmd_param = new QRegExp("^[A-Z]+ :.+$");
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    42
	IRCmsg_number_param = new QRegExp("^:\\S+ [0-9]{3} .+$");
29
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
    43
	IRCmsg_who_cmd_param = new QRegExp("^:\\S+ [A-Z]+ \\S+");
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
    44
	IRCmsg_who_cmd_param_text = new QRegExp("^:\\S+ [A-Z]+ \\S+ :.+$");
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
    45
	isOp = false;
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    46
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    47
	connect(&NetSocket, SIGNAL(readyRead()), this, SLOT(ClientRead()));
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    48
	connect(&NetSocket, SIGNAL(connected()), this, SLOT(OnConnect()));
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    49
	connect(&NetSocket, SIGNAL(disconnected()), this, SLOT(OnDisconnect()));
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    50
	connect(&NetSocket, SIGNAL(error(QAbstractSocket::SocketError)), this,
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    51
			SLOT(displayError(QAbstractSocket::SocketError)));
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    52
}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    53
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    54
void HWNet::ClientRead()
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    55
{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    56
	while (NetSocket.canReadLine())
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    57
	{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    58
		ParseLine(NetSocket.readLine().trimmed());
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    59
	}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    60
}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    61
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    62
void HWNet::displayError(QAbstractSocket::SocketError socketError)
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    63
{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    64
	switch (socketError)
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    65
	{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    66
		case QAbstractSocket::RemoteHostClosedError:
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    67
			break;
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    68
		case QAbstractSocket::HostNotFoundError:
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    69
			QMessageBox::information(0, tr("Error"),
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    70
					tr("The host was not found. Please check the host name and port settings."));
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    71
			break;
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    72
		case QAbstractSocket::ConnectionRefusedError:
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    73
			QMessageBox::information(0, tr("Error"),
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    74
					tr("Connection refused"));
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    75
			break;
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    76
		default:
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    77
			QMessageBox::information(0, tr("Error"),
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    78
					NetSocket.errorString());
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    79
    }
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    80
}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    81
29
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
    82
void HWNet::Connect(const QString & hostName, quint16 port, const QString & nick)
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    83
{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    84
	state = nsConnecting;
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    85
	NetSocket.connectToHost(hostName, port);
29
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
    86
	mynick = nick;
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
    87
	opnick = "";
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
    88
	opCount = 0;
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    89
}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    90
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    91
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    92
void HWNet::OnConnect()
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    93
{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    94
	state = nsConnected;
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    95
	SendNet(QString("USER hwgame 1 2 Hedgewars game"));
29
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
    96
	SendNet(QString("NICK %1").arg(mynick));
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    97
}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    98
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    99
void HWNet::OnDisconnect()
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   100
{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   101
	state = nsDisconnected;
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   102
}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   103
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   104
void HWNet::Perform()
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   105
{
29
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   106
//	SendNet(QString("LIST"));
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   107
	SendNet(QString("JOIN #alex"));
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   108
}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   109
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   110
void HWNet::Disconnect()
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   111
{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   112
	switch (state)
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   113
	{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   114
		case nsDisconnected:
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   115
		{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   116
			break;
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   117
		}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   118
		case nsConnecting:
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   119
		case nsQuitting:
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   120
		{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   121
			NetSocket.disconnect();
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   122
			break;
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   123
		}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   124
		default:
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   125
		{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   126
			state = nsQuitting;
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   127
			SendNet(QString("QUIT :oops"));
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   128
		}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   129
	}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   130
}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   131
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   132
void HWNet::SendNet(const QString & str)
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   133
{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   134
	SendNet(str.toLatin1());
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   135
}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   136
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   137
void HWNet::SendNet(const QByteArray & buf)
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   138
{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   139
	if (buf.size() > 510) return;
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   140
	NetSocket.write(buf);
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   141
	NetSocket.write("\x0d\x0a", 2);
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   142
}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   143
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   144
void HWNet::ParseLine(const QString & msg)
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   145
{
29
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   146
	//QMessageBox::information(0, "", msg);
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   147
	if (IRCmsg_cmd_param->exactMatch(msg))
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   148
	{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   149
		msgcmd_paramHandler(msg);
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   150
	} else
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   151
	if (IRCmsg_number_param->exactMatch(msg))
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   152
	{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   153
		msgnumber_paramHandler(msg);
29
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   154
	} else
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   155
	if (IRCmsg_who_cmd_param->exactMatch(msg))
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   156
	{
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   157
		msgwho_cmd_paramHandler(msg);
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   158
	} else
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   159
	if (IRCmsg_who_cmd_param_text->exactMatch(msg))
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   160
	{
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   161
		msgwho_cmd_param_textHandler(msg);
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   162
	}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   163
}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   164
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   165
void HWNet::msgcmd_paramHandler(const QString & msg)
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   166
{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   167
	QStringList list = msg.split(" :");
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   168
	if (list[0] == "PING")
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   169
	{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   170
		SendNet(QString("PONG %1").arg(list[1]));
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   171
	}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   172
}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   173
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   174
void HWNet::msgnumber_paramHandler(const QString & msg)
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   175
{
29
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   176
	int pos = msg.indexOf(" :");
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   177
	QString text = msg.mid(pos + 2);
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   178
	QStringList list = msg.mid(0, pos).split(" ");
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   179
	bool ok;
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   180
	quint16 number = list[1].toInt(&ok);
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   181
	if (!ok)
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   182
		return ;
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   183
	switch (number)
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   184
	{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   185
		case 001 :
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   186
		{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   187
			Perform();
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   188
			emit Connected();
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   189
			break;
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   190
		}
29
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   191
		case 322 : // RPL_LIST
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   192
		{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   193
			emit AddGame(list[3]);
29
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   194
			break;
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   195
		}
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   196
		case 353 : // RPL_NAMREPLY
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   197
		{
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   198
			QStringList ops = text.split(" ").filter(QRegExp("^@\\S+$"));
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   199
			opCount += ops.size();
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   200
			if (ops.size() == 1)
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   201
			{
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   202
				opnick = ops[0].mid(1);
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   203
			}
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   204
			break;
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   205
		}
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   206
		case 366 : // RPL_ENDOFNAMES
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   207
		{
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   208
			if (opCount != 1)
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   209
			{
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   210
				opnick = "";
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   211
			}
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   212
			SendNet(QString("PRIVMSG #alex :%1 ops here").arg(opCount));
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   213
			opCount = 0;
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   214
			break;
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   215
		}
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   216
		case 432 : // ERR_ERRONEUSNICKNAME
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   217
		case 433 : // ERR_NICKNAMEINUSE
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   218
		{
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   219
			// ask for another nick
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   220
		}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   221
	}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   222
}
29
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   223
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   224
void HWNet::msgwho_cmd_paramHandler(const QString & msg)
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   225
{
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   226
	QStringList list = msg.split(" ");
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   227
	QString who = list[0].mid(1).split("!")[0];
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   228
	if (list[1] == "NICK")
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   229
	{
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   230
		if (mynick == who)
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   231
			mynick = list[2];
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   232
		if (opnick == who)
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   233
			opnick = list[2];
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   234
	}
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   235
}
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   236
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   237
void HWNet::msgwho_cmd_param_textHandler(const QString & msg)
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   238
{
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   239
	int pos = msg.indexOf(" :");
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   240
	QString text = msg.mid(pos + 2);
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   241
	QStringList list = msg.mid(0, pos).split(" ");
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   242
	QString who = list[0].mid(1).split("!")[0];
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   243
	if (list[1] == "PRIVMSG")
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   244
	{
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   245
		SendNet(QString("PRIVMSG #alex :%1 said \"%2\" to %3").arg(who, text, list[2]));
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   246
	}
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   247
}