QTfrontend/netclient.cpp
author unc0rr
Tue, 27 Dec 2005 10:20:55 +0000
changeset 31 99888245a4e8
parent 29 9311259d5242
child 32 78bff13b11c0
permissions -rw-r--r--
Now net game is near available, but exception occurs...
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"
31
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
    36
#include "game.h"
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    37
31
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
    38
#include <QtDebug>
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
    39
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
    40
#define chkp qDebug() << "hw chkp in " << __FILE__ << ":" << __LINE__
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
    41
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
    42
HWNet::HWNet(int Resolution, bool Fullscreen)
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    43
	: QObject()
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    44
{
31
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
    45
	gameResolution = Resolution;
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
    46
	gameFullscreen = Fullscreen;
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    47
	state = nsDisconnected;
31
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
    48
	IRCmsg_cmd_text = new QRegExp("^[A-Z]+ :.+$");
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    49
	IRCmsg_number_param = new QRegExp("^:\\S+ [0-9]{3} .+$");
31
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
    50
	IRCmsg_who_cmd_target = new QRegExp("^:\\S+ [A-Z]+ \\S+$"); // last \\S should mean 'the 1st char is not ":"'
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
    51
	IRCmsg_who_cmd_text = new QRegExp("^:\\S+ [A-Z]+ :.+$");
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
    52
	IRCmsg_who_cmd_target_text = new QRegExp("^:\\S+ [A-Z]+ \\S+ :.+$");
29
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
    53
	isOp = false;
31
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
    54
	teamsCount = 0;
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    55
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    56
	connect(&NetSocket, SIGNAL(readyRead()), this, SLOT(ClientRead()));
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    57
	connect(&NetSocket, SIGNAL(connected()), this, SLOT(OnConnect()));
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    58
	connect(&NetSocket, SIGNAL(disconnected()), this, SLOT(OnDisconnect()));
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    59
	connect(&NetSocket, SIGNAL(error(QAbstractSocket::SocketError)), this,
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    60
			SLOT(displayError(QAbstractSocket::SocketError)));
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    61
}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    62
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    63
void HWNet::ClientRead()
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    64
{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    65
	while (NetSocket.canReadLine())
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    66
	{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    67
		ParseLine(NetSocket.readLine().trimmed());
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    68
	}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    69
}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    70
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    71
void HWNet::displayError(QAbstractSocket::SocketError socketError)
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    72
{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    73
	switch (socketError)
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    74
	{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    75
		case QAbstractSocket::RemoteHostClosedError:
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    76
			break;
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    77
		case QAbstractSocket::HostNotFoundError:
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    78
			QMessageBox::information(0, tr("Error"),
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    79
					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
    80
			break;
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    81
		case QAbstractSocket::ConnectionRefusedError:
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    82
			QMessageBox::information(0, tr("Error"),
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    83
					tr("Connection refused"));
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    84
			break;
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    85
		default:
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    86
			QMessageBox::information(0, tr("Error"),
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    87
					NetSocket.errorString());
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    88
    }
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    89
}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    90
29
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
    91
void HWNet::Connect(const QString & hostName, quint16 port, const QString & nick)
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    92
{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    93
	state = nsConnecting;
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    94
	NetSocket.connectToHost(hostName, port);
29
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
    95
	mynick = nick;
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
    96
	opnick = "";
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
    97
	opCount = 0;
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    98
}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
    99
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   100
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   101
void HWNet::OnConnect()
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   102
{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   103
	state = nsConnected;
31
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   104
	RawSendNet(QString("USER hwgame 1 2 Hedgewars game"));
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   105
	RawSendNet(QString("NICK %1").arg(mynick));
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   106
}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   107
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   108
void HWNet::OnDisconnect()
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   109
{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   110
	state = nsDisconnected;
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   111
}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   112
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   113
void HWNet::Perform()
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   114
{
31
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   115
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   116
}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   117
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   118
void HWNet::JoinGame(const QString & game)
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   119
{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   120
	state = nsJoining;
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   121
	RawSendNet(QString("JOIN %1").arg(game));
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   122
}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   123
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   124
void HWNet::Disconnect()
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   125
{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   126
	switch (state)
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   127
	{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   128
		case nsDisconnected:
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   129
		{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   130
			break;
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   131
		}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   132
		case nsConnecting:
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   133
		case nsQuitting:
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   134
		{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   135
			NetSocket.disconnect();
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   136
			break;
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   137
		}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   138
		default:
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   139
		{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   140
			state = nsQuitting;
31
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   141
			RawSendNet(QString("QUIT :oops"));
28
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
}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   145
31
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   146
void HWNet::RawSendNet(const QString & str)
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   147
{
31
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   148
	RawSendNet(str.toLatin1());
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   149
}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   150
31
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   151
void HWNet::RawSendNet(const QByteArray & buf)
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   152
{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   153
	if (buf.size() > 510) return;
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   154
	NetSocket.write(buf);
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   155
	NetSocket.write("\x0d\x0a", 2);
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   156
}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   157
31
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   158
void HWNet::SendNet(const QByteArray & buf)
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   159
{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   160
	if ((state == nsGaming) || (state == nsStarting))
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   161
	{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   162
		QString msg = QString(buf.toBase64());
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   163
		if (msg == "AUM=")
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   164
		{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   165
			ConfigAsked();
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   166
		} else
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   167
		{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   168
			RawSendNet(QString("PRIVMSG %1 :"MAGIC_CHAR MAGIC_CHAR"%2").arg(channel, msg));
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   169
		}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   170
	}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   171
}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   172
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   173
void HWNet::ParseLine(const QString & msg)
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   174
{
29
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   175
	//QMessageBox::information(0, "", msg);
31
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   176
	if (IRCmsg_cmd_text->exactMatch(msg))
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   177
	{
31
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   178
		msgcmd_textHandler(msg);
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   179
	} else
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   180
	if (IRCmsg_number_param->exactMatch(msg))
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   181
	{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   182
		msgnumber_paramHandler(msg);
29
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   183
	} else
31
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   184
	if (IRCmsg_who_cmd_text->exactMatch(msg))
29
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   185
	{
31
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   186
		msgwho_cmd_textHandler(msg);
29
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   187
	} else
31
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   188
	if (IRCmsg_who_cmd_target->exactMatch(msg))
29
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   189
	{
31
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   190
		msgwho_cmd_targetHandler(msg);
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   191
	} else
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   192
	if (IRCmsg_who_cmd_target_text->exactMatch(msg))
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   193
	{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   194
		msgwho_cmd_target_textHandler(msg);
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   195
	}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   196
}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   197
31
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   198
void HWNet::msgcmd_textHandler(const QString & msg)
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   199
{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   200
	QStringList list = msg.split(" :");
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   201
	if (list[0] == "PING")
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   202
	{
31
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   203
		RawSendNet(QString("PONG %1").arg(list[1]));
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   204
	}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   205
}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   206
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   207
void HWNet::msgnumber_paramHandler(const QString & msg)
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   208
{
29
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   209
	int pos = msg.indexOf(" :");
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   210
	QString text = msg.mid(pos + 2);
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   211
	QStringList list = msg.mid(0, pos).split(" ");
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   212
	bool ok;
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   213
	quint16 number = list[1].toInt(&ok);
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   214
	if (!ok)
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   215
		return ;
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   216
	switch (number)
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   217
	{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   218
		case 001 :
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   219
		{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   220
			Perform();
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   221
			emit Connected();
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   222
			break;
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   223
		}
29
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   224
		case 322 : // RPL_LIST
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   225
		{
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   226
			emit AddGame(list[3]);
29
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   227
			break;
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   228
		}
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   229
		case 353 : // RPL_NAMREPLY
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   230
		{
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   231
			QStringList ops = text.split(" ").filter(QRegExp("^@\\S+$"));
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   232
			opCount += ops.size();
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   233
			if (ops.size() == 1)
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
				opnick = ops[0].mid(1);
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
			break;
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
		case 366 : // RPL_ENDOFNAMES
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   240
		{
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   241
			if (opCount != 1)
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   242
			{
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   243
				opnick = "";
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
			opCount = 0;
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   246
			break;
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   247
		}
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   248
		case 432 : // ERR_ERRONEUSNICKNAME
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   249
		case 433 : // ERR_NICKNAMEINUSE
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   250
		{
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   251
			// ask for another nick
28
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   252
		}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   253
	}
59f7db859b8a - clear demos list before adding items
unc0rr
parents:
diff changeset
   254
}
29
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   255
31
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   256
void HWNet::msgwho_cmd_targetHandler(const QString & msg)
29
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   257
{
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   258
	QStringList list = msg.split(" ");
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   259
	QString who = list[0].mid(1).split("!")[0];
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   260
	if (list[1] == "NICK")
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   261
	{
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   262
		if (mynick == who)
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   263
			mynick = list[2];
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   264
		if (opnick == who)
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   265
			opnick = list[2];
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   266
	}
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   267
}
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   268
31
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   269
void HWNet::msgwho_cmd_textHandler(const QString & msg)
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   270
{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   271
	int pos = msg.indexOf(" :");
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   272
	QString text = msg.mid(pos + 2);
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   273
	QStringList list = msg.mid(0, pos).split(" ");
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   274
	QString who = list[0].mid(1).split("!")[0];
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   275
	if (list[1] == "JOIN")
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   276
	{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   277
		if (who == mynick)
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   278
		{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   279
			channel = text;
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   280
			state = nsJoined;
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   281
			emit EnteredGame();
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   282
			RawSendNet(QString("PRIVMSG %1 :Hello!").arg(channel));
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   283
		}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   284
	}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   285
}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   286
void HWNet::msgwho_cmd_target_textHandler(const QString & msg)
29
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   287
{
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   288
	int pos = msg.indexOf(" :");
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   289
	QString text = msg.mid(pos + 2);
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   290
	QStringList list = msg.mid(0, pos).split(" ");
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   291
	QString who = list[0].mid(1).split("!")[0];
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   292
	if (list[1] == "PRIVMSG")
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   293
	{
31
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   294
		if (list[2] == opnick)
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   295
		{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   296
			hwp_opmsg(who, text);
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   297
		} else
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   298
		if (list[2] == channel)
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   299
		{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   300
			hwp_chanmsg(who, text);
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   301
		}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   302
	}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   303
}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   304
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   305
void HWNet::hwp_opmsg(const QString & who, const QString & msg)
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   306
{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   307
	if (state != nsJoined)
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   308
		return ;
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   309
	if (!msg.startsWith(MAGIC_CHAR))
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   310
		return ;
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   311
	QStringList list = msg.split(MAGIC_CHAR, QString::SkipEmptyParts);
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   312
	if (list[0] == "A")
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   313
	{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   314
		list.removeFirst();
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   315
		if (list.size() != 9)
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   316
			return ;
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   317
		if (teamsCount < 5)
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   318
		{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   319
			teams[teamsCount].nick = who;
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   320
			teams[teamsCount].hhs = list;
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   321
			teamsCount++;
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   322
			QString teamnames;
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   323
			for(int i = 0; i < teamsCount; i++)
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   324
			{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   325
				teamnames += MAGIC_CHAR;
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   326
				teamnames += teams[i].hhs[0];
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   327
			}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   328
			RawSendNet(QString("PRIVMSG %1 :"MAGIC_CHAR"Teams%2").arg(channel, teamnames));
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   329
		}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   330
	}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   331
}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   332
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   333
void HWNet::ConfigAsked()
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   334
{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   335
	configasks++;
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   336
	if (configasks == playerscnt)
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   337
	{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   338
		quint32 color = 65535;
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   339
		for (int i = 0; i < teamsCount; i++)
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   340
		{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   341
chkp;			SENDCFGSTRNET("eaddteam");
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   342
			QString msg;
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   343
			msg = MAGIC_CHAR "T" MAGIC_CHAR + teams[i].nick + MAGIC_CHAR + teams[i].hhs.join(MAGIC_CHAR);
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   344
			RawSendNet(QString("PRIVMSG %1 :%2").arg(channel, msg));
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   345
			hwp_chanmsg(mynick, msg);
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   346
			SENDCFGSTRNET(QString("ecolor %1").arg(color));
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   347
			SENDCFGSTRNET("eadd hh0 0");
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   348
			SENDCFGSTRNET("eadd hh1 0");
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   349
			SENDCFGSTRNET("eadd hh2 0");
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   350
			color <<= 8;
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   351
		}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   352
chkp;		SENDCFGSTRNET("!");
29
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   353
	}
9311259d5242 More work on net game, still far from complete
unc0rr
parents: 28
diff changeset
   354
}
31
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   355
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   356
void HWNet::hwp_chanmsg(const QString & who, const QString & msg)
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   357
{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   358
	if ((state < nsJoined) || (state > nsGaming))
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   359
	{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   360
		return ;
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   361
	}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   362
	if ((state == nsJoined) && (msg.startsWith(MAGIC_CHAR"Start!"MAGIC_CHAR)) && (who == opnick))
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   363
	{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   364
		state = nsStarting;
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   365
		RunGame(msg.mid(7));
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   366
		return ;
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   367
	}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   368
	if ((state == nsStarting) && (msg == MAGIC_CHAR MAGIC_CHAR "AUM="))
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   369
	{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   370
		if (mynick == opnick) ConfigAsked();
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   371
		return ;
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   372
	}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   373
	if ((state == nsStarting) && (msg.startsWith(MAGIC_CHAR"T"MAGIC_CHAR)))
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   374
	{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   375
		NetTeamAdded(msg.mid(3));
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   376
	}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   377
	if (state != nsGaming)
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   378
	{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   379
		return;
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   380
	}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   381
	if (msg.startsWith(MAGIC_CHAR MAGIC_CHAR)) // HWP message
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   382
	{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   383
		emit FromNet(QByteArray::fromBase64(msg.mid(2).toLocal8Bit()));
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   384
	} else // smth other
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   385
	{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   386
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   387
	}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   388
}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   389
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   390
void HWNet::NetTeamAdded(const QString & msg)
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   391
{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   392
	QStringList list = msg.split(MAGIC_CHAR, QString::SkipEmptyParts);
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   393
	if (list.size() != 10)
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   394
		return ;
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   395
	if (list[0] == mynick)
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   396
	{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   397
chkp;		emit LocalCFG(list[1]);
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   398
	} else
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   399
	{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   400
chkp;		SENDCFGSTRLOC("erdriven");
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   401
		SENDCFGSTRLOC(QString("ename team %1").arg(list[2]));
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   402
		for (int i = 0; i < 8; i++)
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   403
		{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   404
			SENDCFGSTRLOC(QString("ename hh%1").arg(i) + list[i + 3]);
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   405
		}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   406
chkp;	}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   407
}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   408
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   409
void HWNet::AddTeam(const HWTeam & team)
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   410
{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   411
	if (state != nsJoined)
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   412
	{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   413
		return ;
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   414
	}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   415
	RawSendNet(QString("PRIVMSG %1 :").arg(opnick) + MAGIC_CHAR "A" MAGIC_CHAR +
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   416
			team.TeamName + MAGIC_CHAR + team.HHName[0] + MAGIC_CHAR + team.HHName[1] + MAGIC_CHAR +
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   417
			team.HHName[2] + MAGIC_CHAR + team.HHName[3] + MAGIC_CHAR + team.HHName[4] + MAGIC_CHAR +
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   418
			team.HHName[5] + MAGIC_CHAR + team.HHName[6] + MAGIC_CHAR + team.HHName[7]);
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   419
}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   420
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   421
void HWNet::StartGame()
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   422
{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   423
	if ((opnick != mynick) || (state != nsJoined))
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   424
	{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   425
		return ;
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   426
	}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   427
	QStringList players;
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   428
	for (int i = 0; i < teamsCount; i++)
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   429
	{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   430
		if (!players.contains(teams[i].nick))
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   431
		{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   432
			players.append(teams[i].nick);
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   433
		}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   434
	}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   435
	playerscnt = players.size();
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   436
	configasks = 0;
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   437
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   438
	QString seed;
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   439
	seedgen.GenRNDStr(seed, 10);
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   440
	QString msg = QString(MAGIC_CHAR"Start!"MAGIC_CHAR"%1").arg(seed);
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   441
	RawSendNet(QString("PRIVMSG %1 :%2").arg(channel, msg));
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   442
	hwp_chanmsg(mynick, msg);
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   443
}
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   444
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   445
void HWNet::RunGame(const QString & seed)
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   446
{
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   447
	HWGame * game = new HWGame(gameResolution, gameFullscreen);
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   448
	connect(game, SIGNAL(SendNet(const QByteArray &)), this, SLOT(SendNet(const QByteArray &)));
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   449
	connect(this, SIGNAL(FromNet(const QByteArray &)), game, SLOT(FromNet(const QByteArray &)));
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   450
	connect(this, SIGNAL(LocalCFG(const QString &)), game, SLOT(LocalCFG(const QString &)));
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   451
	game->StartNet(seed);
99888245a4e8 Now net game is near available, but exception occurs...
unc0rr
parents: 29
diff changeset
   452
}