QTfrontend/netclient.cpp
changeset 97 e7c1df9cce2c
parent 85 44d9045b26ff
child 125 0532e70b1ce4
equal deleted inserted replaced
96:aeeb4da6b157 97:e7c1df9cce2c
   138 	}
   138 	}
   139 }
   139 }
   140 
   140 
   141 void HWNet::RawSendNet(const QString & str)
   141 void HWNet::RawSendNet(const QString & str)
   142 {
   142 {
   143 	RawSendNet(str.toLatin1());
   143 	RawSendNet(str.toUtf8());
   144 }
   144 }
   145 
   145 
   146 void HWNet::RawSendNet(const QByteArray & buf)
   146 void HWNet::RawSendNet(const QByteArray & buf)
   147 {
   147 {
   148 	if (buf.size() > 510) return;
   148 	if (buf.size() > 510) return;
   260 			break;
   260 			break;
   261 		}
   261 		}
   262 		case 432 : // ERR_ERRONEUSNICKNAME
   262 		case 432 : // ERR_ERRONEUSNICKNAME
   263 		case 433 : // ERR_NICKNAMEINUSE
   263 		case 433 : // ERR_NICKNAMEINUSE
   264 		{
   264 		{
       
   265 			QMessageBox::information(0, "Your net nickname is in use or cannot be used", msg);
   265 			// ask for another nick
   266 			// ask for another nick
   266 		}
   267 		}
   267 	}
   268 	}
   268 }
   269 }
   269 
   270 
   350 {
   351 {
   351 	configasks++;
   352 	configasks++;
   352 	if (configasks == playerscnt)
   353 	if (configasks == playerscnt)
   353 	{
   354 	{
   354 		quint32 color = 65535;
   355 		quint32 color = 65535;
   355 		for (int i = 0; i < teamsCount; i++)
       
   356 		{
       
   357 			QString msg;
       
   358 			msg = MAGIC_CHAR "T" MAGIC_CHAR + teams[i].nick + MAGIC_CHAR + teams[i].hhs.join(MAGIC_CHAR);
       
   359 			RawSendNet(QString("PRIVMSG %1 :%2").arg(channel, msg));
       
   360 			hwp_chanmsg(mynick, msg);
       
   361 			QByteArray cache;
       
   362 			#define ADD(a) { \
   356 			#define ADD(a) { \
   363 							QByteArray strmsg; \
   357 							QByteArray strmsg; \
   364 							strmsg.append(a); \
   358 							strmsg.append(a); \
   365 							quint8 sz = strmsg.size(); \
   359 							quint8 sz = strmsg.size(); \
   366 							cache.append(QByteArray((char *)&sz, 1)); \
   360 							cache.append(QByteArray((char *)&sz, 1)); \
   367 							cache.append(strmsg); \
   361 							cache.append(strmsg); \
   368 							}
   362 							}
       
   363 		{
       
   364 			QByteArray cache;
       
   365 			ADD("eseed " + seed);
       
   366 			ADD("e$gmflags 0");
       
   367 			ADD("etheme steel");
       
   368 			QString _msg = MAGIC_CHAR MAGIC_CHAR + QString(cache.toBase64());
       
   369 			RawSendNet(QString("PRIVMSG %1 :%2").arg(channel, _msg));
       
   370 			hwp_chanmsg(mynick, _msg);
       
   371 		}
       
   372 		for (int i = 0; i < teamsCount; i++)
       
   373 		{
       
   374 			QString msg;
       
   375 			msg = MAGIC_CHAR "T" MAGIC_CHAR + teams[i].nick + MAGIC_CHAR + teams[i].hhs.join(MAGIC_CHAR);
       
   376 			RawSendNet(QString("PRIVMSG %1 :%2").arg(channel, msg));
       
   377 			hwp_chanmsg(mynick, msg);
       
   378 			QByteArray cache;
   369 			ADD(QString("ecolor %1").arg(color));
   379 			ADD(QString("ecolor %1").arg(color));
   370 			ADD("eadd hh0 0");
   380 			ADD("eadd hh0 0");
   371 			ADD("eadd hh1 0");
   381 			ADD("eadd hh1 0");
   372 			ADD("eadd hh2 0");
   382 			ADD("eadd hh2 0");
   373 			ADD("eadd hh3 0");
   383 			ADD("eadd hh3 0");
   374 			ADD("eadd hh4 0");
   384 			ADD("eadd hh4 0");
   375 			#undef ADD
   385 			#undef ADD
   376 			QString _msg = MAGIC_CHAR MAGIC_CHAR + QString(cache.toBase64());
   386 			QString _msg = MAGIC_CHAR MAGIC_CHAR + QString(cache.toBase64());
       
   387 			RawSendNet(QString("PRIVMSG %1 :%2").arg(channel, _msg));
   377 			hwp_chanmsg(mynick, _msg);
   388 			hwp_chanmsg(mynick, _msg);
   378 			RawSendNet(QString("PRIVMSG %1 :").arg(channel) + _msg);
       
   379 			color <<= 8;
   389 			color <<= 8;
   380 		}
   390 		}
   381 		SENDCFGSTRNET("!");
   391 		SENDCFGSTRNET("!");
   382 	}
   392 	}
   383 }
   393 }
   388 	{
   398 	{
   389 		return ;
   399 		return ;
   390 	}
   400 	}
   391 	if (state == nsJoined)
   401 	if (state == nsJoined)
   392 	{
   402 	{
   393 		if (msg.startsWith(MAGIC_CHAR"Start!"MAGIC_CHAR) && (who == opnick))
   403 		if (msg.startsWith(MAGIC_CHAR"Start!") && (who == opnick))
   394 		{
   404 		{
   395 			state = nsStarting;
   405 			state = nsStarting;
   396 			RunGame(msg.mid(8));
   406 			RunGame();
   397 			return ;
   407 			return ;
   398 		}
   408 		}
   399 		if (msg.startsWith(MAGIC_CHAR"="MAGIC_CHAR) && (who == opnick))
   409 		if (msg.startsWith(MAGIC_CHAR"="MAGIC_CHAR) && (who == opnick))
   400 		{
   410 		{
   401 			emit ChangeInTeams(msg.mid(3).split(MAGIC_CHAR));
   411 			emit ChangeInTeams(msg.mid(3).split(MAGIC_CHAR));
   424 	{
   434 	{
   425 		return;
   435 		return;
   426 	}
   436 	}
   427 	if (msg.startsWith(MAGIC_CHAR MAGIC_CHAR)) // HWP message
   437 	if (msg.startsWith(MAGIC_CHAR MAGIC_CHAR)) // HWP message
   428 	{
   438 	{
   429 		QByteArray em = QByteArray::fromBase64(msg.mid(2).toLocal8Bit());
   439 		QByteArray em = QByteArray::fromBase64(msg.mid(2).toAscii());
   430 		emit FromNet(em);
   440 		emit FromNet(em);
   431 	} else // smth other
   441 	} else // smth other
   432 	{
   442 	{
   433 
   443 
   434 	}
   444 	}
   481 		}
   491 		}
   482 	}
   492 	}
   483 	playerscnt = players.size();
   493 	playerscnt = players.size();
   484 	configasks = 0;
   494 	configasks = 0;
   485 
   495 
   486 	QString seed;
       
   487 	seedgen.GenRNDStr(seed, 10);
   496 	seedgen.GenRNDStr(seed, 10);
   488 	QString msg = QString(MAGIC_CHAR"Start!"MAGIC_CHAR"%1").arg(seed);
   497 	QString msg = QString(MAGIC_CHAR"Start!");
   489 	RawSendNet(QString("PRIVMSG %1 :%2").arg(channel, msg));
   498 	RawSendNet(QString("PRIVMSG %1 :%2").arg(channel, msg));
   490 	hwp_chanmsg(mynick, msg);
   499 	hwp_chanmsg(mynick, msg);
   491 }
   500 }
   492 
   501 
   493 void HWNet::RunGame(const QString & seed)
   502 void HWNet::RunGame()
   494 {
   503 {
   495 	HWGame * game = new HWGame(config, 0);
   504 	HWGame * game = new HWGame(config, 0);
   496 	connect(game, SIGNAL(SendNet(const QByteArray &)), this, SLOT(SendNet(const QByteArray &)));
   505 	connect(game, SIGNAL(SendNet(const QByteArray &)), this, SLOT(SendNet(const QByteArray &)));
   497 	connect(this, SIGNAL(FromNet(const QByteArray &)), game, SLOT(FromNet(const QByteArray &)));
   506 	connect(this, SIGNAL(FromNet(const QByteArray &)), game, SLOT(FromNet(const QByteArray &)));
   498 	connect(this, SIGNAL(LocalCFG(const QString &)), game, SLOT(LocalCFG(const QString &)));
   507 	connect(this, SIGNAL(LocalCFG(const QString &)), game, SLOT(LocalCFG(const QString &)));
   499 	game->StartNet(seed);
   508 	game->StartNet();
   500 }
   509 }