QTfrontend/newnetclient.cpp
author unc0rr
Wed, 08 Oct 2008 13:40:29 +0000
changeset 1313 f4c54e9e1b8c
parent 1311 49beb1221c0b
child 1315 c2f09811bb8c
permissions -rw-r--r--
- Introduce a bit of state miachine in client code (should be more robust and verbosive now) - Prepare for creating and joining rooms code
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
     1
/*
1066
1f1b3686a2b0 Update copyright headers a bit
unc0rr
parents: 884
diff changeset
     2
 * Hedgewars, a free turn based strategy game
883
07a568ba44e0 Update copyright info in source files headers
unc0rr
parents: 747
diff changeset
     3
 * Copyright (c) 2006-2008 Ulyanov Igor <iulyanov@gmail.com>
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
     4
 *
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
     8
 *
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    12
 * GNU General Public License for more details.
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    13
 *
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    17
 */
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    18
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    19
#include <QMessageBox>
1189
f66cdbbfc4b6 Fix compile under Ubuntu (why it compiles everywhere else?)
unc0rr
parents: 1083
diff changeset
    20
#include <QDebug>
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    21
697
44f167938201 pre-alpha network weapons selection
displacer
parents: 660
diff changeset
    22
#include "hwconsts.h"
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    23
#include "newnetclient.h"
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    24
#include "proto.h"
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    25
#include "gameuiconfig.h"
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    26
#include "game.h"
334
85eacbd9827f protocol changes
displacer
parents: 332
diff changeset
    27
#include "gamecfgwidget.h"
347
6521e1b2cd40 more correct remove net teams
displacer
parents: 341
diff changeset
    28
#include "teamselect.h"
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    29
1082
596b1dcdc1df - Modify network protocol to use new delimiter
unc0rr
parents: 1081
diff changeset
    30
char delimeter='\n';
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    31
339
7535ab6c3820 Run game message added, team and config info provided for net game
displacer
parents: 338
diff changeset
    32
HWNewNet::HWNewNet(GameUIConfig * config, GameCFGWidget* pGameCFGWidget, TeamSelWidget* pTeamSelWidget) :
334
85eacbd9827f protocol changes
displacer
parents: 332
diff changeset
    33
  config(config),
85eacbd9827f protocol changes
displacer
parents: 332
diff changeset
    34
  m_pGameCFGWidget(pGameCFGWidget),
339
7535ab6c3820 Run game message added, team and config info provided for net game
displacer
parents: 338
diff changeset
    35
  m_pTeamSelWidget(pTeamSelWidget),
383
09a8795105a4 some disconnect and remove teams bugfixes
displacer
parents: 382
diff changeset
    36
  isChief(false),
1313
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
    37
  m_game_connected(false),
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
    38
  loginStep(0),
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
    39
  netClientState(0)
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    40
{
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    41
  connect(&NetSocket, SIGNAL(readyRead()), this, SLOT(ClientRead()));
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    42
  connect(&NetSocket, SIGNAL(connected()), this, SLOT(OnConnect()));
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    43
  connect(&NetSocket, SIGNAL(disconnected()), this, SLOT(OnDisconnect()));
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    44
  connect(&NetSocket, SIGNAL(error(QAbstractSocket::SocketError)), this,
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    45
	  SLOT(displayError(QAbstractSocket::SocketError)));
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    46
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    47
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    48
void HWNewNet::Connect(const QString & hostName, quint16 port, const QString & nick)
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    49
{
655
e58a77556878 - Temporary set delimiter to *, as \t seems to be endline now in Qt
unc0rr
parents: 574
diff changeset
    50
  mynick = nick;
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    51
  NetSocket.connectToHost(hostName, port);
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    52
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    53
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    54
void HWNewNet::Disconnect()
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    55
{
1311
49beb1221c0b - Add stub page for rooms list
unc0rr
parents: 1310
diff changeset
    56
  m_game_connected = false;
383
09a8795105a4 some disconnect and remove teams bugfixes
displacer
parents: 382
diff changeset
    57
  NetSocket.disconnectFromHost();
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    58
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    59
1082
596b1dcdc1df - Modify network protocol to use new delimiter
unc0rr
parents: 1081
diff changeset
    60
void HWNewNet::CreateRoom(const QString & room)
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    61
{
1313
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
    62
	if(netClientState != 2)
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
    63
	{
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
    64
		qDebug("Illegal try to create room!");
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
    65
		return;
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
    66
	}
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
    67
	
1082
596b1dcdc1df - Modify network protocol to use new delimiter
unc0rr
parents: 1081
diff changeset
    68
	RawSendNet(QString("CREATE%1%2").arg(delimeter).arg(room));
1313
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
    69
	isChief = true;
1082
596b1dcdc1df - Modify network protocol to use new delimiter
unc0rr
parents: 1081
diff changeset
    70
}
596b1dcdc1df - Modify network protocol to use new delimiter
unc0rr
parents: 1081
diff changeset
    71
596b1dcdc1df - Modify network protocol to use new delimiter
unc0rr
parents: 1081
diff changeset
    72
void HWNewNet::JoinRoom(const QString & room)
596b1dcdc1df - Modify network protocol to use new delimiter
unc0rr
parents: 1081
diff changeset
    73
{
1313
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
    74
	if(netClientState != 2)
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
    75
	{
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
    76
		qDebug("Illegal try to join room!");
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
    77
		return;
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
    78
	}
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
    79
	
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
    80
	loginStep++;
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
    81
1082
596b1dcdc1df - Modify network protocol to use new delimiter
unc0rr
parents: 1081
diff changeset
    82
	RawSendNet(QString("JOIN%1%2").arg(delimeter).arg(room));
1313
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
    83
	m_pGameCFGWidget->setEnabled(false);
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
    84
	m_pTeamSelWidget->setNonInteractive();
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
    85
	isChief = false;
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    86
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    87
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    88
void HWNewNet::AddTeam(const HWTeam & team)
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
    89
{
1311
49beb1221c0b - Add stub page for rooms list
unc0rr
parents: 1310
diff changeset
    90
	QString cmd = QString("ADDTEAM") + delimeter +
382
e7220e48ead1 colors changing config fully working (still need disabling in slaves)
displacer
parents: 373
diff changeset
    91
	     team.TeamName + delimeter +
e7220e48ead1 colors changing config fully working (still need disabling in slaves)
displacer
parents: 373
diff changeset
    92
	     team.teamColor.name() + delimeter +
443
eec37eb7f5db fort, grave and difficulty information for net team
displacer
parents: 431
diff changeset
    93
	     team.Grave + delimeter +
eec37eb7f5db fort, grave and difficulty information for net team
displacer
parents: 431
diff changeset
    94
	     team.Fort + delimeter +
1245
d2eca4a053f5 Send hats info via net. Hats implementation complete now.
unc0rr
parents: 1189
diff changeset
    95
	     QString::number(team.difficulty);
d2eca4a053f5 Send hats info via net. Hats implementation complete now.
unc0rr
parents: 1189
diff changeset
    96
d2eca4a053f5 Send hats info via net. Hats implementation complete now.
unc0rr
parents: 1189
diff changeset
    97
	for(int i = 0; i < 8; ++i)
d2eca4a053f5 Send hats info via net. Hats implementation complete now.
unc0rr
parents: 1189
diff changeset
    98
	{
d2eca4a053f5 Send hats info via net. Hats implementation complete now.
unc0rr
parents: 1189
diff changeset
    99
		cmd.append(delimeter);
d2eca4a053f5 Send hats info via net. Hats implementation complete now.
unc0rr
parents: 1189
diff changeset
   100
		cmd.append(team.HHName[i]);
d2eca4a053f5 Send hats info via net. Hats implementation complete now.
unc0rr
parents: 1189
diff changeset
   101
		cmd.append(delimeter);
d2eca4a053f5 Send hats info via net. Hats implementation complete now.
unc0rr
parents: 1189
diff changeset
   102
		cmd.append(team.HHHat[i]);
d2eca4a053f5 Send hats info via net. Hats implementation complete now.
unc0rr
parents: 1189
diff changeset
   103
	}
d2eca4a053f5 Send hats info via net. Hats implementation complete now.
unc0rr
parents: 1189
diff changeset
   104
	RawSendNet(cmd);
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   105
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   106
347
6521e1b2cd40 more correct remove net teams
displacer
parents: 341
diff changeset
   107
void HWNewNet::RemoveTeam(const HWTeam & team)
6521e1b2cd40 more correct remove net teams
displacer
parents: 341
diff changeset
   108
{
1311
49beb1221c0b - Add stub page for rooms list
unc0rr
parents: 1310
diff changeset
   109
  RawSendNet(QString("REMOVETEAM") + delimeter + team.TeamName);
401
bcebe3921740 some colors and network protocol fixes
displacer
parents: 399
diff changeset
   110
  m_networkToLocalteams.remove(m_networkToLocalteams.key(team.TeamName));
347
6521e1b2cd40 more correct remove net teams
displacer
parents: 341
diff changeset
   111
}
6521e1b2cd40 more correct remove net teams
displacer
parents: 341
diff changeset
   112
1311
49beb1221c0b - Add stub page for rooms list
unc0rr
parents: 1310
diff changeset
   113
void HWNewNet::Ready()
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   114
{
1311
49beb1221c0b - Add stub page for rooms list
unc0rr
parents: 1310
diff changeset
   115
  RawSendNet(QString("READY"));
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   116
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   117
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   118
void HWNewNet::SendNet(const QByteArray & buf)
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   119
{
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   120
  QString msg = QString(buf.toBase64());
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   121
1311
49beb1221c0b - Add stub page for rooms list
unc0rr
parents: 1310
diff changeset
   122
  RawSendNet(QString("GAMEMSG%1%2").arg(delimeter).arg(msg));
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   123
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   124
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   125
void HWNewNet::RawSendNet(const QString & str)
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   126
{
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   127
  RawSendNet(str.toUtf8());
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   128
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   129
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   130
void HWNewNet::RawSendNet(const QByteArray & buf)
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   131
{
1308
d5dcd6cfa5e2 Fix another server failure (when second client in room disconnects)
unc0rr
parents: 1307
diff changeset
   132
  qDebug() << "Client: " << QString(buf).split("\n");
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   133
  NetSocket.write(buf);
1082
596b1dcdc1df - Modify network protocol to use new delimiter
unc0rr
parents: 1081
diff changeset
   134
  NetSocket.write("\n\n", 2);
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   135
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   136
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   137
void HWNewNet::ClientRead()
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   138
{
1082
596b1dcdc1df - Modify network protocol to use new delimiter
unc0rr
parents: 1081
diff changeset
   139
	while (NetSocket.canReadLine()) {
596b1dcdc1df - Modify network protocol to use new delimiter
unc0rr
parents: 1081
diff changeset
   140
		QString s = QString::fromUtf8(NetSocket.readLine().trimmed());
596b1dcdc1df - Modify network protocol to use new delimiter
unc0rr
parents: 1081
diff changeset
   141
596b1dcdc1df - Modify network protocol to use new delimiter
unc0rr
parents: 1081
diff changeset
   142
		if (s.size() == 0) {
596b1dcdc1df - Modify network protocol to use new delimiter
unc0rr
parents: 1081
diff changeset
   143
			ParseCmd(cmdbuf);
596b1dcdc1df - Modify network protocol to use new delimiter
unc0rr
parents: 1081
diff changeset
   144
			cmdbuf.clear();
596b1dcdc1df - Modify network protocol to use new delimiter
unc0rr
parents: 1081
diff changeset
   145
		} else
596b1dcdc1df - Modify network protocol to use new delimiter
unc0rr
parents: 1081
diff changeset
   146
			cmdbuf << s;
596b1dcdc1df - Modify network protocol to use new delimiter
unc0rr
parents: 1081
diff changeset
   147
	}
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   148
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   149
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   150
void HWNewNet::OnConnect()
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   151
{
1310
4616e15d566f Get rid of "internet" network game mode
unc0rr
parents: 1308
diff changeset
   152
	RawSendNet(QString("NICK%1%2").arg(delimeter).arg(mynick));
4616e15d566f Get rid of "internet" network game mode
unc0rr
parents: 1308
diff changeset
   153
	RawSendNet(QString("PROTO%1%2").arg(delimeter).arg(*cProtoVer));
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   154
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   155
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   156
void HWNewNet::OnDisconnect()
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   157
{
338
d1e75dcd285f multiple teams now available per host (still alpha)
displacer
parents: 335
diff changeset
   158
  //emit ChangeInTeams(QStringList());
383
09a8795105a4 some disconnect and remove teams bugfixes
displacer
parents: 382
diff changeset
   159
  if(m_game_connected) emit Disconnected();
09a8795105a4 some disconnect and remove teams bugfixes
displacer
parents: 382
diff changeset
   160
  m_game_connected=false;
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   161
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   162
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   163
void HWNewNet::displayError(QAbstractSocket::SocketError socketError)
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   164
{
1302
4290ba4a14ca Remove deprecated stuff
unc0rr
parents: 1245
diff changeset
   165
	switch (socketError) {
4290ba4a14ca Remove deprecated stuff
unc0rr
parents: 1245
diff changeset
   166
		case QAbstractSocket::RemoteHostClosedError:
4290ba4a14ca Remove deprecated stuff
unc0rr
parents: 1245
diff changeset
   167
			break;
4290ba4a14ca Remove deprecated stuff
unc0rr
parents: 1245
diff changeset
   168
		case QAbstractSocket::HostNotFoundError:
4290ba4a14ca Remove deprecated stuff
unc0rr
parents: 1245
diff changeset
   169
			QMessageBox::information(0, tr("Error"),
4290ba4a14ca Remove deprecated stuff
unc0rr
parents: 1245
diff changeset
   170
					tr("The host was not found. Please check the host name and port settings."));
4290ba4a14ca Remove deprecated stuff
unc0rr
parents: 1245
diff changeset
   171
			break;
4290ba4a14ca Remove deprecated stuff
unc0rr
parents: 1245
diff changeset
   172
		case QAbstractSocket::ConnectionRefusedError:
4290ba4a14ca Remove deprecated stuff
unc0rr
parents: 1245
diff changeset
   173
			QMessageBox::information(0, tr("Error"),
4290ba4a14ca Remove deprecated stuff
unc0rr
parents: 1245
diff changeset
   174
					tr("Connection refused"));
4290ba4a14ca Remove deprecated stuff
unc0rr
parents: 1245
diff changeset
   175
			break;
4290ba4a14ca Remove deprecated stuff
unc0rr
parents: 1245
diff changeset
   176
		default:
4290ba4a14ca Remove deprecated stuff
unc0rr
parents: 1245
diff changeset
   177
			QMessageBox::information(0, tr("Error"),
4290ba4a14ca Remove deprecated stuff
unc0rr
parents: 1245
diff changeset
   178
					NetSocket.errorString());
4290ba4a14ca Remove deprecated stuff
unc0rr
parents: 1245
diff changeset
   179
		}
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   180
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   181
1082
596b1dcdc1df - Modify network protocol to use new delimiter
unc0rr
parents: 1081
diff changeset
   182
void HWNewNet::ParseCmd(const QStringList & lst)
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   183
{
1305
453882eb4467 - Fix build of server (has some bugs now)
unc0rr
parents: 1302
diff changeset
   184
	qDebug() << "Server: " << lst;
453882eb4467 - Fix build of server (has some bugs now)
unc0rr
parents: 1302
diff changeset
   185
453882eb4467 - Fix build of server (has some bugs now)
unc0rr
parents: 1302
diff changeset
   186
	if(!lst.size())
453882eb4467 - Fix build of server (has some bugs now)
unc0rr
parents: 1302
diff changeset
   187
	{
453882eb4467 - Fix build of server (has some bugs now)
unc0rr
parents: 1302
diff changeset
   188
		qWarning("Net client: Bad message");
453882eb4467 - Fix build of server (has some bugs now)
unc0rr
parents: 1302
diff changeset
   189
		return;
453882eb4467 - Fix build of server (has some bugs now)
unc0rr
parents: 1302
diff changeset
   190
	}
320
1ee7f087195a - HWMapContainer sets and stores the theme
unc0rr
parents: 319
diff changeset
   191
1308
d5dcd6cfa5e2 Fix another server failure (when second client in room disconnects)
unc0rr
parents: 1307
diff changeset
   192
	if ((lst[0] == "NICK") || (lst[0] == "PROTO"))
1313
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
   193
	{
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
   194
		loginStep++;
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
   195
		if (loginStep == 2)
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
   196
		{
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
   197
			netClientState = 2;
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
   198
			RawSendNet(QString("LIST"));
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
   199
		}
1308
d5dcd6cfa5e2 Fix another server failure (when second client in room disconnects)
unc0rr
parents: 1307
diff changeset
   200
		return ;
1313
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
   201
	}
1308
d5dcd6cfa5e2 Fix another server failure (when second client in room disconnects)
unc0rr
parents: 1307
diff changeset
   202
1305
453882eb4467 - Fix build of server (has some bugs now)
unc0rr
parents: 1302
diff changeset
   203
	if (lst[0] == "ERROR") {
453882eb4467 - Fix build of server (has some bugs now)
unc0rr
parents: 1302
diff changeset
   204
		if (lst.size() == 2)
1307
ce26e16d18ab - Now actually fix
unc0rr
parents: 1305
diff changeset
   205
			QMessageBox::information(0, 0, "Error: " + lst[1]);
1305
453882eb4467 - Fix build of server (has some bugs now)
unc0rr
parents: 1302
diff changeset
   206
		else
453882eb4467 - Fix build of server (has some bugs now)
unc0rr
parents: 1302
diff changeset
   207
			QMessageBox::information(0, 0, "Unknown error");
453882eb4467 - Fix build of server (has some bugs now)
unc0rr
parents: 1302
diff changeset
   208
		return;
453882eb4467 - Fix build of server (has some bugs now)
unc0rr
parents: 1302
diff changeset
   209
	}
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   210
1307
ce26e16d18ab - Now actually fix
unc0rr
parents: 1305
diff changeset
   211
	if (lst[0] == "WARNING") {
ce26e16d18ab - Now actually fix
unc0rr
parents: 1305
diff changeset
   212
		if (lst.size() == 2)
ce26e16d18ab - Now actually fix
unc0rr
parents: 1305
diff changeset
   213
			QMessageBox::information(0, 0, "Warning: " + lst[1]);
ce26e16d18ab - Now actually fix
unc0rr
parents: 1305
diff changeset
   214
		else
ce26e16d18ab - Now actually fix
unc0rr
parents: 1305
diff changeset
   215
			QMessageBox::information(0, 0, "Unknown warning");
ce26e16d18ab - Now actually fix
unc0rr
parents: 1305
diff changeset
   216
		return;
ce26e16d18ab - Now actually fix
unc0rr
parents: 1305
diff changeset
   217
	}
ce26e16d18ab - Now actually fix
unc0rr
parents: 1305
diff changeset
   218
1308
d5dcd6cfa5e2 Fix another server failure (when second client in room disconnects)
unc0rr
parents: 1307
diff changeset
   219
	if (lst[0] == "CONNECTED") {
1313
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
   220
		netClientState = 1;
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
   221
		m_game_connected = true;
1308
d5dcd6cfa5e2 Fix another server failure (when second client in room disconnects)
unc0rr
parents: 1307
diff changeset
   222
		emit Connected();
d5dcd6cfa5e2 Fix another server failure (when second client in room disconnects)
unc0rr
parents: 1307
diff changeset
   223
		return;
d5dcd6cfa5e2 Fix another server failure (when second client in room disconnects)
unc0rr
parents: 1307
diff changeset
   224
	}
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   225
1313
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
   226
	if (lst[0] == "ROOMS") {
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
   227
		QStringList tmp = lst;
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
   228
		tmp.removeFirst();
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
   229
		emit roomsList(tmp);
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
   230
		return;
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
   231
	}
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
   232
1308
d5dcd6cfa5e2 Fix another server failure (when second client in room disconnects)
unc0rr
parents: 1307
diff changeset
   233
	if (lst[0] == "CHAT_STRING") {
d5dcd6cfa5e2 Fix another server failure (when second client in room disconnects)
unc0rr
parents: 1307
diff changeset
   234
		if(lst.size() < 3)
d5dcd6cfa5e2 Fix another server failure (when second client in room disconnects)
unc0rr
parents: 1307
diff changeset
   235
		{
d5dcd6cfa5e2 Fix another server failure (when second client in room disconnects)
unc0rr
parents: 1307
diff changeset
   236
		qWarning("Net: Empty CHAT_STRING message");
d5dcd6cfa5e2 Fix another server failure (when second client in room disconnects)
unc0rr
parents: 1307
diff changeset
   237
		return;
d5dcd6cfa5e2 Fix another server failure (when second client in room disconnects)
unc0rr
parents: 1307
diff changeset
   238
		}
d5dcd6cfa5e2 Fix another server failure (when second client in room disconnects)
unc0rr
parents: 1307
diff changeset
   239
		QStringList tmp = lst;
d5dcd6cfa5e2 Fix another server failure (when second client in room disconnects)
unc0rr
parents: 1307
diff changeset
   240
		tmp.removeFirst();
d5dcd6cfa5e2 Fix another server failure (when second client in room disconnects)
unc0rr
parents: 1307
diff changeset
   241
		emit chatStringFromNet(tmp);
d5dcd6cfa5e2 Fix another server failure (when second client in room disconnects)
unc0rr
parents: 1307
diff changeset
   242
		return;
d5dcd6cfa5e2 Fix another server failure (when second client in room disconnects)
unc0rr
parents: 1307
diff changeset
   243
	}
453
4b1236759402 simple net cha added
displacer
parents: 448
diff changeset
   244
338
d1e75dcd285f multiple teams now available per host (still alpha)
displacer
parents: 335
diff changeset
   245
  if (lst[0] == "ADDTEAM:") {
1245
d2eca4a053f5 Send hats info via net. Hats implementation complete now.
unc0rr
parents: 1189
diff changeset
   246
    if(lst.size() < 22)
574
1cafd9eb1a21 - Update copyright header
unc0rr
parents: 573
diff changeset
   247
    {
1cafd9eb1a21 - Update copyright header
unc0rr
parents: 573
diff changeset
   248
	  qWarning("Net: Too short ADDTEAM message");
1cafd9eb1a21 - Update copyright header
unc0rr
parents: 573
diff changeset
   249
	  return;
1cafd9eb1a21 - Update copyright header
unc0rr
parents: 573
diff changeset
   250
    }
1082
596b1dcdc1df - Modify network protocol to use new delimiter
unc0rr
parents: 1081
diff changeset
   251
    QStringList tmp = lst;
596b1dcdc1df - Modify network protocol to use new delimiter
unc0rr
parents: 1081
diff changeset
   252
    tmp.removeFirst();
596b1dcdc1df - Modify network protocol to use new delimiter
unc0rr
parents: 1081
diff changeset
   253
    emit AddNetTeam(tmp);
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   254
    return;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   255
  }
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   256
347
6521e1b2cd40 more correct remove net teams
displacer
parents: 341
diff changeset
   257
  if (lst[0] == "REMOVETEAM:") {
573
e0cf483e68d6 - Highlight more undefined behavior of net protocol
unc0rr
parents: 486
diff changeset
   258
    if(lst.size() < 3)
e0cf483e68d6 - Highlight more undefined behavior of net protocol
unc0rr
parents: 486
diff changeset
   259
    {
e0cf483e68d6 - Highlight more undefined behavior of net protocol
unc0rr
parents: 486
diff changeset
   260
      qWarning("Net: Bad REMOVETEAM message");
e0cf483e68d6 - Highlight more undefined behavior of net protocol
unc0rr
parents: 486
diff changeset
   261
      return;
e0cf483e68d6 - Highlight more undefined behavior of net protocol
unc0rr
parents: 486
diff changeset
   262
    }
352
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 349
diff changeset
   263
    m_pTeamSelWidget->removeNetTeam(HWTeam(lst[1], lst[2].toUInt()));
347
6521e1b2cd40 more correct remove net teams
displacer
parents: 341
diff changeset
   264
    return;
6521e1b2cd40 more correct remove net teams
displacer
parents: 341
diff changeset
   265
  }
6521e1b2cd40 more correct remove net teams
displacer
parents: 341
diff changeset
   266
1308
d5dcd6cfa5e2 Fix another server failure (when second client in room disconnects)
unc0rr
parents: 1307
diff changeset
   267
	if(lst[0]=="JOINED") {
d5dcd6cfa5e2 Fix another server failure (when second client in room disconnects)
unc0rr
parents: 1307
diff changeset
   268
		if(lst.size() < 2)
d5dcd6cfa5e2 Fix another server failure (when second client in room disconnects)
unc0rr
parents: 1307
diff changeset
   269
		{
d5dcd6cfa5e2 Fix another server failure (when second client in room disconnects)
unc0rr
parents: 1307
diff changeset
   270
			qWarning("Net: Bad JOINED message");
d5dcd6cfa5e2 Fix another server failure (when second client in room disconnects)
unc0rr
parents: 1307
diff changeset
   271
			return;
d5dcd6cfa5e2 Fix another server failure (when second client in room disconnects)
unc0rr
parents: 1307
diff changeset
   272
		}
1311
49beb1221c0b - Add stub page for rooms list
unc0rr
parents: 1310
diff changeset
   273
		
1308
d5dcd6cfa5e2 Fix another server failure (when second client in room disconnects)
unc0rr
parents: 1307
diff changeset
   274
		for(int i = 1; i < lst.size(); ++i)
1311
49beb1221c0b - Add stub page for rooms list
unc0rr
parents: 1310
diff changeset
   275
		{
1313
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
   276
			if (lst[i] == mynick)
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
   277
			{
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
   278
				netClientState = 3;
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
   279
				emit EnteredGame();
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
   280
				ConfigAsked();
f4c54e9e1b8c - Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents: 1311
diff changeset
   281
			}
1308
d5dcd6cfa5e2 Fix another server failure (when second client in room disconnects)
unc0rr
parents: 1307
diff changeset
   282
			emit nickAdded(lst[i]);
1311
49beb1221c0b - Add stub page for rooms list
unc0rr
parents: 1310
diff changeset
   283
		}
1308
d5dcd6cfa5e2 Fix another server failure (when second client in room disconnects)
unc0rr
parents: 1307
diff changeset
   284
		return;
d5dcd6cfa5e2 Fix another server failure (when second client in room disconnects)
unc0rr
parents: 1307
diff changeset
   285
	}
455
925891c52e40 hedgehogs num bugfix for netgame
displacer
parents: 453
diff changeset
   286
1310
4616e15d566f Get rid of "internet" network game mode
unc0rr
parents: 1308
diff changeset
   287
	if(lst[0]=="LEFT") {
4616e15d566f Get rid of "internet" network game mode
unc0rr
parents: 1308
diff changeset
   288
		if(lst.size() < 2)
4616e15d566f Get rid of "internet" network game mode
unc0rr
parents: 1308
diff changeset
   289
		{
4616e15d566f Get rid of "internet" network game mode
unc0rr
parents: 1308
diff changeset
   290
			qWarning("Net: Bad LEFT message");
4616e15d566f Get rid of "internet" network game mode
unc0rr
parents: 1308
diff changeset
   291
			return;
4616e15d566f Get rid of "internet" network game mode
unc0rr
parents: 1308
diff changeset
   292
		}
4616e15d566f Get rid of "internet" network game mode
unc0rr
parents: 1308
diff changeset
   293
		emit nickRemoved(lst[1]);
4616e15d566f Get rid of "internet" network game mode
unc0rr
parents: 1308
diff changeset
   294
		return;
4616e15d566f Get rid of "internet" network game mode
unc0rr
parents: 1308
diff changeset
   295
	}
461
105af110b0e6 chatWidget with layout
displacer
parents: 455
diff changeset
   296
339
7535ab6c3820 Run game message added, team and config info provided for net game
displacer
parents: 338
diff changeset
   297
  if (lst[0] == "RUNGAME") {
396
70dfd02845af return after rungame
displacer
parents: 395
diff changeset
   298
    RunGame();
70dfd02845af return after rungame
displacer
parents: 395
diff changeset
   299
    return;
339
7535ab6c3820 Run game message added, team and config info provided for net game
displacer
parents: 338
diff changeset
   300
  }
7535ab6c3820 Run game message added, team and config info provided for net game
displacer
parents: 338
diff changeset
   301
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   302
  if (lst[0] == "CONFIGURED") {
1082
596b1dcdc1df - Modify network protocol to use new delimiter
unc0rr
parents: 1081
diff changeset
   303
    QStringList tmp = lst;
596b1dcdc1df - Modify network protocol to use new delimiter
unc0rr
parents: 1081
diff changeset
   304
    tmp.removeFirst();
596b1dcdc1df - Modify network protocol to use new delimiter
unc0rr
parents: 1081
diff changeset
   305
    if(tmp.size() < 6)
573
e0cf483e68d6 - Highlight more undefined behavior of net protocol
unc0rr
parents: 486
diff changeset
   306
    {
e0cf483e68d6 - Highlight more undefined behavior of net protocol
unc0rr
parents: 486
diff changeset
   307
      qWarning("Net: Bad CONFIGURED message");
e0cf483e68d6 - Highlight more undefined behavior of net protocol
unc0rr
parents: 486
diff changeset
   308
      return;
e0cf483e68d6 - Highlight more undefined behavior of net protocol
unc0rr
parents: 486
diff changeset
   309
    }
1082
596b1dcdc1df - Modify network protocol to use new delimiter
unc0rr
parents: 1081
diff changeset
   310
    emit seedChanged(tmp[0]);
596b1dcdc1df - Modify network protocol to use new delimiter
unc0rr
parents: 1081
diff changeset
   311
    emit mapChanged(tmp[1]);
596b1dcdc1df - Modify network protocol to use new delimiter
unc0rr
parents: 1081
diff changeset
   312
    emit themeChanged(tmp[2]);
596b1dcdc1df - Modify network protocol to use new delimiter
unc0rr
parents: 1081
diff changeset
   313
    emit initHealthChanged(tmp[3].toUInt());
596b1dcdc1df - Modify network protocol to use new delimiter
unc0rr
parents: 1081
diff changeset
   314
    emit turnTimeChanged(tmp[4].toUInt());
596b1dcdc1df - Modify network protocol to use new delimiter
unc0rr
parents: 1081
diff changeset
   315
    emit fortsModeChanged(tmp[5].toInt() != 0);
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   316
    return;
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   317
  }
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   318
354
60e4af0a4375 network to local teams map, addteams from server before team config bug, fixed some segfaults
displacer
parents: 352
diff changeset
   319
  if(lst[0]=="TEAM_ACCEPTED") {
573
e0cf483e68d6 - Highlight more undefined behavior of net protocol
unc0rr
parents: 486
diff changeset
   320
    if(lst.size() < 3)
e0cf483e68d6 - Highlight more undefined behavior of net protocol
unc0rr
parents: 486
diff changeset
   321
    {
e0cf483e68d6 - Highlight more undefined behavior of net protocol
unc0rr
parents: 486
diff changeset
   322
      qWarning("Net: Bad TEAM_ACCEPTED message");
e0cf483e68d6 - Highlight more undefined behavior of net protocol
unc0rr
parents: 486
diff changeset
   323
      return;
e0cf483e68d6 - Highlight more undefined behavior of net protocol
unc0rr
parents: 486
diff changeset
   324
    }
354
60e4af0a4375 network to local teams map, addteams from server before team config bug, fixed some segfaults
displacer
parents: 352
diff changeset
   325
    m_networkToLocalteams.insert(lst[2].toUInt(), lst[1]);
373
df912aab6b7e network team add can be denied by server
displacer
parents: 372
diff changeset
   326
    m_pTeamSelWidget->changeTeamStatus(lst[1]);
354
60e4af0a4375 network to local teams map, addteams from server before team config bug, fixed some segfaults
displacer
parents: 352
diff changeset
   327
    return;
60e4af0a4375 network to local teams map, addteams from server before team config bug, fixed some segfaults
displacer
parents: 352
diff changeset
   328
  }
60e4af0a4375 network to local teams map, addteams from server before team config bug, fixed some segfaults
displacer
parents: 352
diff changeset
   329
329
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   330
  if (lst[0] == "CONFIG_PARAM") {
573
e0cf483e68d6 - Highlight more undefined behavior of net protocol
unc0rr
parents: 486
diff changeset
   331
    if(lst.size() < 3)
e0cf483e68d6 - Highlight more undefined behavior of net protocol
unc0rr
parents: 486
diff changeset
   332
    {
e0cf483e68d6 - Highlight more undefined behavior of net protocol
unc0rr
parents: 486
diff changeset
   333
      qWarning("Net: Bad CONFIG_PARAM message");
e0cf483e68d6 - Highlight more undefined behavior of net protocol
unc0rr
parents: 486
diff changeset
   334
      return;
e0cf483e68d6 - Highlight more undefined behavior of net protocol
unc0rr
parents: 486
diff changeset
   335
    }
329
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   336
  	if (lst[1] == "SEED") {
332
10080f681118 isChiefClient is now correct :)
displacer
parents: 329
diff changeset
   337
	  emit seedChanged(lst[2]);
329
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   338
	  return;
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   339
  	}
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   340
  	if (lst[1] == "MAP") {
332
10080f681118 isChiefClient is now correct :)
displacer
parents: 329
diff changeset
   341
	  emit mapChanged(lst[2]);
329
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   342
	  return;
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   343
  	}
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   344
  	if (lst[1] == "THEME") {
332
10080f681118 isChiefClient is now correct :)
displacer
parents: 329
diff changeset
   345
	  emit themeChanged(lst[2]);
329
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   346
	  return;
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   347
  	}
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   348
  	if (lst[1] == "HEALTH") {
332
10080f681118 isChiefClient is now correct :)
displacer
parents: 329
diff changeset
   349
	  emit initHealthChanged(lst[2].toUInt());
329
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   350
	  return;
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   351
  	}
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   352
  	if (lst[1] == "TURNTIME") {
332
10080f681118 isChiefClient is now correct :)
displacer
parents: 329
diff changeset
   353
	  emit turnTimeChanged(lst[2].toUInt());
329
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   354
	  return;
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   355
  	}
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   356
  	if (lst[1] == "FORTSMODE") {
332
10080f681118 isChiefClient is now correct :)
displacer
parents: 329
diff changeset
   357
	  emit fortsModeChanged(lst[2].toInt() != 0);
329
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   358
	  return;
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   359
  	}
697
44f167938201 pre-alpha network weapons selection
displacer
parents: 660
diff changeset
   360
	if (lst[1] == "AMMO") {
703
424297e3165a weapon names transmitted over network
displacer
parents: 697
diff changeset
   361
	  if(lst.size() < 4) return;
424297e3165a weapon names transmitted over network
displacer
parents: 697
diff changeset
   362
	  emit ammoChanged(lst[3], lst[2]);
697
44f167938201 pre-alpha network weapons selection
displacer
parents: 660
diff changeset
   363
	  return;
44f167938201 pre-alpha network weapons selection
displacer
parents: 660
diff changeset
   364
	}
401
bcebe3921740 some colors and network protocol fixes
displacer
parents: 399
diff changeset
   365
	QStringList hhTmpList=lst[1].split('+');
bcebe3921740 some colors and network protocol fixes
displacer
parents: 399
diff changeset
   366
  	if (hhTmpList[0] == "TEAM_COLOR") {
bcebe3921740 some colors and network protocol fixes
displacer
parents: 399
diff changeset
   367
	  HWTeam tmptm(hhTmpList[1], hhTmpList[2].toUInt());
bcebe3921740 some colors and network protocol fixes
displacer
parents: 399
diff changeset
   368
	  if(m_networkToLocalteams.find(hhTmpList[2].toUInt())!=m_networkToLocalteams.end()) {
bcebe3921740 some colors and network protocol fixes
displacer
parents: 399
diff changeset
   369
	    tmptm=HWTeam(hhTmpList[1]); // local team should be changed
372
4bac77f8cd38 network colors (alpha)
displacer
parents: 362
diff changeset
   370
	  }
401
bcebe3921740 some colors and network protocol fixes
displacer
parents: 399
diff changeset
   371
	  tmptm.teamColor=QColor(lst[2]);
372
4bac77f8cd38 network colors (alpha)
displacer
parents: 362
diff changeset
   372
	  emit teamColorChanged(tmptm);
4bac77f8cd38 network colors (alpha)
displacer
parents: 362
diff changeset
   373
	  return;
4bac77f8cd38 network colors (alpha)
displacer
parents: 362
diff changeset
   374
  	}
401
bcebe3921740 some colors and network protocol fixes
displacer
parents: 399
diff changeset
   375
  	if (hhTmpList[0] == "HHNUM") {
399
c7da1bd32b4e more correct network hhnum
displacer
parents: 396
diff changeset
   376
	  HWTeam tmptm(hhTmpList[1], hhTmpList[2].toUInt());
c7da1bd32b4e more correct network hhnum
displacer
parents: 396
diff changeset
   377
	  if(m_networkToLocalteams.find(hhTmpList[2].toUInt())!=m_networkToLocalteams.end()) {
c7da1bd32b4e more correct network hhnum
displacer
parents: 396
diff changeset
   378
	    tmptm=HWTeam(hhTmpList[1]); // local team should be changed
c7da1bd32b4e more correct network hhnum
displacer
parents: 396
diff changeset
   379
	  }
c7da1bd32b4e more correct network hhnum
displacer
parents: 396
diff changeset
   380
	  tmptm.numHedgehogs=lst[2].toUInt();
c7da1bd32b4e more correct network hhnum
displacer
parents: 396
diff changeset
   381
	  emit hhnumChanged(tmptm);
c7da1bd32b4e more correct network hhnum
displacer
parents: 396
diff changeset
   382
	  return;
c7da1bd32b4e more correct network hhnum
displacer
parents: 396
diff changeset
   383
  	}
1082
596b1dcdc1df - Modify network protocol to use new delimiter
unc0rr
parents: 1081
diff changeset
   384
    qWarning() << "Net: Unknown 'CONFIG_PARAM' message:" << lst;
329
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   385
    return;
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   386
  }
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   387
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   388
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   389
  // should be kinda game states, which don't allow "GAMEMSG:" at configure step,
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   390
  // "CONNECTED" at round phase, etc.
1310
4616e15d566f Get rid of "internet" network game mode
unc0rr
parents: 1308
diff changeset
   391
  if (lst[0] == "GAMEMSG") {
573
e0cf483e68d6 - Highlight more undefined behavior of net protocol
unc0rr
parents: 486
diff changeset
   392
    if(lst.size() < 2)
e0cf483e68d6 - Highlight more undefined behavior of net protocol
unc0rr
parents: 486
diff changeset
   393
    {
1310
4616e15d566f Get rid of "internet" network game mode
unc0rr
parents: 1308
diff changeset
   394
      qWarning("Net: Bad GAMEMSG message");
573
e0cf483e68d6 - Highlight more undefined behavior of net protocol
unc0rr
parents: 486
diff changeset
   395
      return;
e0cf483e68d6 - Highlight more undefined behavior of net protocol
unc0rr
parents: 486
diff changeset
   396
    }
329
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   397
    QByteArray em = QByteArray::fromBase64(lst[1].toAscii());
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   398
    emit FromNet(em);
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   399
    return;
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   400
  }
573
e0cf483e68d6 - Highlight more undefined behavior of net protocol
unc0rr
parents: 486
diff changeset
   401
1082
596b1dcdc1df - Modify network protocol to use new delimiter
unc0rr
parents: 1081
diff changeset
   402
  qWarning() << "Net: Unknown message:" << lst;
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   403
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   404
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   405
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   406
void HWNewNet::ConfigAsked()
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   407
{
1310
4616e15d566f Get rid of "internet" network game mode
unc0rr
parents: 1308
diff changeset
   408
	QString map = m_pGameCFGWidget->getCurrentMap();
4616e15d566f Get rid of "internet" network game mode
unc0rr
parents: 1308
diff changeset
   409
	if (map.size())
4616e15d566f Get rid of "internet" network game mode
unc0rr
parents: 1308
diff changeset
   410
		onMapChanged(map);
574
1cafd9eb1a21 - Update copyright header
unc0rr
parents: 573
diff changeset
   411
1310
4616e15d566f Get rid of "internet" network game mode
unc0rr
parents: 1308
diff changeset
   412
	onSeedChanged(m_pGameCFGWidget->getCurrentSeed());
4616e15d566f Get rid of "internet" network game mode
unc0rr
parents: 1308
diff changeset
   413
	onThemeChanged(m_pGameCFGWidget->getCurrentTheme());
4616e15d566f Get rid of "internet" network game mode
unc0rr
parents: 1308
diff changeset
   414
	onInitHealthChanged(m_pGameCFGWidget->getInitHealth());
4616e15d566f Get rid of "internet" network game mode
unc0rr
parents: 1308
diff changeset
   415
	onTurnTimeChanged(m_pGameCFGWidget->getTurnTime());
4616e15d566f Get rid of "internet" network game mode
unc0rr
parents: 1308
diff changeset
   416
	onFortsModeChanged(m_pGameCFGWidget->getGameFlags() & 0x1);
4616e15d566f Get rid of "internet" network game mode
unc0rr
parents: 1308
diff changeset
   417
	// always initialize with default ammo (also avoiding complicated cross-class dependencies)
4616e15d566f Get rid of "internet" network game mode
unc0rr
parents: 1308
diff changeset
   418
	onWeaponsNameChanged("Default", cDefaultAmmoStore->mid(10));
315
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   419
}
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   420
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   421
void HWNewNet::RunGame()
73003488240b client/server net pre-alpha
displacer
parents:
diff changeset
   422
{
1310
4616e15d566f Get rid of "internet" network game mode
unc0rr
parents: 1308
diff changeset
   423
	emit AskForRunGame();
431
79ac59673df3 - Two more land templates
unc0rr
parents: 407
diff changeset
   424
}
79ac59673df3 - Two more land templates
unc0rr
parents: 407
diff changeset
   425
352
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 349
diff changeset
   426
void HWNewNet::onHedgehogsNumChanged(const HWTeam& team)
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 349
diff changeset
   427
{
455
925891c52e40 hedgehogs num bugfix for netgame
displacer
parents: 453
diff changeset
   428
  RawSendNet(QString("HHNUM%1%2%1%3%1%4").arg(delimeter).arg(team.TeamName)\
354
60e4af0a4375 network to local teams map, addteams from server before team config bug, fixed some segfaults
displacer
parents: 352
diff changeset
   429
	     .arg(team.getNetID() ? team.getNetID() : m_networkToLocalteams.key(team.TeamName))\
60e4af0a4375 network to local teams map, addteams from server before team config bug, fixed some segfaults
displacer
parents: 352
diff changeset
   430
	     .arg(team.numHedgehogs));
352
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 349
diff changeset
   431
}
4665bfe25470 first buggy hedgehogs num net change
displacer
parents: 349
diff changeset
   432
372
4bac77f8cd38 network colors (alpha)
displacer
parents: 362
diff changeset
   433
void HWNewNet::onTeamColorChanged(const HWTeam& team)
4bac77f8cd38 network colors (alpha)
displacer
parents: 362
diff changeset
   434
{
401
bcebe3921740 some colors and network protocol fixes
displacer
parents: 399
diff changeset
   435
  RawSendNet(QString("CONFIG_PARAM%1TEAM_COLOR+%2+%3%1%4").arg(delimeter).arg(team.TeamName)\
372
4bac77f8cd38 network colors (alpha)
displacer
parents: 362
diff changeset
   436
	     .arg(team.getNetID() ? team.getNetID() : m_networkToLocalteams.key(team.TeamName))\
4bac77f8cd38 network colors (alpha)
displacer
parents: 362
diff changeset
   437
	     .arg(team.teamColor.name()));
4bac77f8cd38 network colors (alpha)
displacer
parents: 362
diff changeset
   438
}
4bac77f8cd38 network colors (alpha)
displacer
parents: 362
diff changeset
   439
329
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   440
void HWNewNet::onSeedChanged(const QString & seed)
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   441
{
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   442
  RawSendNet(QString("CONFIG_PARAM%1SEED%1%2").arg(delimeter).arg(seed));
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   443
}
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   444
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   445
void HWNewNet::onMapChanged(const QString & map)
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   446
{
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   447
  RawSendNet(QString("CONFIG_PARAM%1MAP%1%2").arg(delimeter).arg(map));
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   448
}
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   449
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   450
void HWNewNet::onThemeChanged(const QString & theme)
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   451
{
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   452
  RawSendNet(QString("CONFIG_PARAM%1THEME%1%2").arg(delimeter).arg(theme));
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   453
}
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   454
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   455
void HWNewNet::onInitHealthChanged(quint32 health)
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   456
{
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   457
  RawSendNet(QString("CONFIG_PARAM%1HEALTH%1%2").arg(delimeter).arg(health));
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   458
}
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   459
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   460
void HWNewNet::onTurnTimeChanged(quint32 time)
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   461
{
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   462
  RawSendNet(QString("CONFIG_PARAM%1TURNTIME%1%2").arg(delimeter).arg(time));
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   463
}
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   464
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   465
void HWNewNet::onFortsModeChanged(bool value)
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   466
{
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   467
  RawSendNet(QString("CONFIG_PARAM%1FORTSMODE%1%2").arg(delimeter).arg(value));
4c3aad46baa5 Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents: 322
diff changeset
   468
}
453
4b1236759402 simple net cha added
displacer
parents: 448
diff changeset
   469
703
424297e3165a weapon names transmitted over network
displacer
parents: 697
diff changeset
   470
void HWNewNet::onWeaponsNameChanged(const QString& name, const QString& ammo)
697
44f167938201 pre-alpha network weapons selection
displacer
parents: 660
diff changeset
   471
{
703
424297e3165a weapon names transmitted over network
displacer
parents: 697
diff changeset
   472
  RawSendNet(QString("CONFIG_PARAM%1AMMO%1%2%1%3").arg(delimeter).arg(ammo).arg(name));
697
44f167938201 pre-alpha network weapons selection
displacer
parents: 660
diff changeset
   473
}
44f167938201 pre-alpha network weapons selection
displacer
parents: 660
diff changeset
   474
453
4b1236759402 simple net cha added
displacer
parents: 448
diff changeset
   475
void HWNewNet::chatLineToNet(const QString& str)
4b1236759402 simple net cha added
displacer
parents: 448
diff changeset
   476
{
4b1236759402 simple net cha added
displacer
parents: 448
diff changeset
   477
  if(str!="") {
4b1236759402 simple net cha added
displacer
parents: 448
diff changeset
   478
    RawSendNet(QString("CHAT_STRING")+delimeter+mynick+delimeter+str);
4b1236759402 simple net cha added
displacer
parents: 448
diff changeset
   479
    emit(chatStringFromNet(QStringList(mynick) << str));
4b1236759402 simple net cha added
displacer
parents: 448
diff changeset
   480
  }
4b1236759402 simple net cha added
displacer
parents: 448
diff changeset
   481
}