QTfrontend/netclient.cpp
changeset 32 78bff13b11c0
parent 31 99888245a4e8
child 36 a803a00a3272
equal deleted inserted replaced
31:99888245a4e8 32:78bff13b11c0
    33 
    33 
    34 #include <QMessageBox>
    34 #include <QMessageBox>
    35 #include "netclient.h"
    35 #include "netclient.h"
    36 #include "game.h"
    36 #include "game.h"
    37 
    37 
    38 #include <QtDebug>
       
    39 
       
    40 #define chkp qDebug() << "hw chkp in " << __FILE__ << ":" << __LINE__
       
    41 
       
    42 HWNet::HWNet(int Resolution, bool Fullscreen)
    38 HWNet::HWNet(int Resolution, bool Fullscreen)
    43 	: QObject()
    39 	: QObject()
    44 {
    40 {
    45 	gameResolution = Resolution;
    41 	gameResolution = Resolution;
    46 	gameFullscreen = Fullscreen;
    42 	gameFullscreen = Fullscreen;
   158 void HWNet::SendNet(const QByteArray & buf)
   154 void HWNet::SendNet(const QByteArray & buf)
   159 {
   155 {
   160 	if ((state == nsGaming) || (state == nsStarting))
   156 	if ((state == nsGaming) || (state == nsStarting))
   161 	{
   157 	{
   162 		QString msg = QString(buf.toBase64());
   158 		QString msg = QString(buf.toBase64());
   163 		if (msg == "AUM=")
   159 		if ((msg == "AUM=") && (mynick == opnick))
   164 		{
   160 		{
   165 			ConfigAsked();
   161 			ConfigAsked();
       
   162 		} else
       
   163 		if (msg == "AT8=")
       
   164 		{
       
   165 			// its ping ("?")
   166 		} else
   166 		} else
   167 		{
   167 		{
   168 			RawSendNet(QString("PRIVMSG %1 :"MAGIC_CHAR MAGIC_CHAR"%2").arg(channel, msg));
   168 			RawSendNet(QString("PRIVMSG %1 :"MAGIC_CHAR MAGIC_CHAR"%2").arg(channel, msg));
   169 		}
   169 		}
   170 	}
   170 	}
   323 			for(int i = 0; i < teamsCount; i++)
   323 			for(int i = 0; i < teamsCount; i++)
   324 			{
   324 			{
   325 				teamnames += MAGIC_CHAR;
   325 				teamnames += MAGIC_CHAR;
   326 				teamnames += teams[i].hhs[0];
   326 				teamnames += teams[i].hhs[0];
   327 			}
   327 			}
   328 			RawSendNet(QString("PRIVMSG %1 :"MAGIC_CHAR"Teams%2").arg(channel, teamnames));
   328 			QString tmsg = QString(MAGIC_CHAR"=%2").arg(teamnames);
       
   329 			RawSendNet(QString("PRIVMSG %1 :").arg(channel) + tmsg);
       
   330 			hwp_chanmsg(mynick, tmsg);
   329 		}
   331 		}
   330 	}
   332 	}
   331 }
   333 }
   332 
   334 
   333 void HWNet::ConfigAsked()
   335 void HWNet::ConfigAsked()
   336 	if (configasks == playerscnt)
   338 	if (configasks == playerscnt)
   337 	{
   339 	{
   338 		quint32 color = 65535;
   340 		quint32 color = 65535;
   339 		for (int i = 0; i < teamsCount; i++)
   341 		for (int i = 0; i < teamsCount; i++)
   340 		{
   342 		{
   341 chkp;			SENDCFGSTRNET("eaddteam");
       
   342 			QString msg;
   343 			QString msg;
   343 			msg = MAGIC_CHAR "T" MAGIC_CHAR + teams[i].nick + MAGIC_CHAR + teams[i].hhs.join(MAGIC_CHAR);
   344 			msg = MAGIC_CHAR "T" MAGIC_CHAR + teams[i].nick + MAGIC_CHAR + teams[i].hhs.join(MAGIC_CHAR);
   344 			RawSendNet(QString("PRIVMSG %1 :%2").arg(channel, msg));
   345 			RawSendNet(QString("PRIVMSG %1 :%2").arg(channel, msg));
   345 			hwp_chanmsg(mynick, msg);
   346 			hwp_chanmsg(mynick, msg);
   346 			SENDCFGSTRNET(QString("ecolor %1").arg(color));
   347 			SENDCFGSTRNET(QString("ecolor %1").arg(color));
   347 			SENDCFGSTRNET("eadd hh0 0");
   348 			SENDCFGSTRNET("eadd hh0 0");
   348 			SENDCFGSTRNET("eadd hh1 0");
   349 			SENDCFGSTRNET("eadd hh1 0");
   349 			SENDCFGSTRNET("eadd hh2 0");
   350 			SENDCFGSTRNET("eadd hh2 0");
   350 			color <<= 8;
   351 			color <<= 8;
   351 		}
   352 		}
   352 chkp;		SENDCFGSTRNET("!");
   353 		SENDCFGSTRNET("!");
       
   354 		state = nsGaming;
   353 	}
   355 	}
   354 }
   356 }
   355 
   357 
   356 void HWNet::hwp_chanmsg(const QString & who, const QString & msg)
   358 void HWNet::hwp_chanmsg(const QString & who, const QString & msg)
   357 {
   359 {
   358 	if ((state < nsJoined) || (state > nsGaming))
   360 	if ((state < nsJoined) || (state > nsGaming))
   359 	{
   361 	{
   360 		return ;
   362 		return ;
   361 	}
   363 	}
   362 	if ((state == nsJoined) && (msg.startsWith(MAGIC_CHAR"Start!"MAGIC_CHAR)) && (who == opnick))
   364 	if (state == nsJoined)
   363 	{
   365 	{
   364 		state = nsStarting;
   366 		if (msg.startsWith(MAGIC_CHAR"Start!"MAGIC_CHAR) && (who == opnick))
   365 		RunGame(msg.mid(7));
   367 		{
   366 		return ;
   368 			state = nsStarting;
   367 	}
   369 			RunGame(msg.mid(7));
   368 	if ((state == nsStarting) && (msg == MAGIC_CHAR MAGIC_CHAR "AUM="))
   370 			return ;
   369 	{
   371 		}
   370 		if (mynick == opnick) ConfigAsked();
   372 		if (msg.startsWith(MAGIC_CHAR"="MAGIC_CHAR) && (who == opnick))
   371 		return ;
   373 		{
   372 	}
   374 			emit ChangeInTeams(msg.mid(3).split(MAGIC_CHAR));
   373 	if ((state == nsStarting) && (msg.startsWith(MAGIC_CHAR"T"MAGIC_CHAR)))
   375 		}
   374 	{
   376 	}
   375 		NetTeamAdded(msg.mid(3));
   377 	if (state == nsStarting)
   376 	}
   378 	{
   377 	if (state != nsGaming)
   379 		if (msg == MAGIC_CHAR MAGIC_CHAR "AUM=")
       
   380 		{
       
   381 			if (mynick == opnick) ConfigAsked();
       
   382 			return ;
       
   383 		}
       
   384 		if (msg == MAGIC_CHAR MAGIC_CHAR "ASE=")
       
   385 		{
       
   386 			state = nsGaming;
       
   387 		}
       
   388 		if (msg.startsWith(MAGIC_CHAR"T"MAGIC_CHAR))
       
   389 		{
       
   390 			NetTeamAdded(msg.mid(3));
       
   391 		}
       
   392 	}
       
   393 	if ((state != nsGaming) && (state != nsStarting))
   378 	{
   394 	{
   379 		return;
   395 		return;
   380 	}
   396 	}
   381 	if (msg.startsWith(MAGIC_CHAR MAGIC_CHAR)) // HWP message
   397 	if (msg.startsWith(MAGIC_CHAR MAGIC_CHAR)) // HWP message
   382 	{
   398 	{
   383 		emit FromNet(QByteArray::fromBase64(msg.mid(2).toLocal8Bit()));
   399 		QByteArray em = QByteArray::fromBase64(msg.mid(2).toLocal8Bit());
       
   400 		emit FromNet(em);
   384 	} else // smth other
   401 	} else // smth other
   385 	{
   402 	{
   386 
   403 
   387 	}
   404 	}
   388 }
   405 }
   390 void HWNet::NetTeamAdded(const QString & msg)
   407 void HWNet::NetTeamAdded(const QString & msg)
   391 {
   408 {
   392 	QStringList list = msg.split(MAGIC_CHAR, QString::SkipEmptyParts);
   409 	QStringList list = msg.split(MAGIC_CHAR, QString::SkipEmptyParts);
   393 	if (list.size() != 10)
   410 	if (list.size() != 10)
   394 		return ;
   411 		return ;
       
   412 	SENDCFGSTRLOC("eaddteam");
   395 	if (list[0] == mynick)
   413 	if (list[0] == mynick)
   396 	{
   414 	{
   397 chkp;		emit LocalCFG(list[1]);
   415 		emit LocalCFG(list[1]);
   398 	} else
   416 	} else
   399 	{
   417 	{
   400 chkp;		SENDCFGSTRLOC("erdriven");
   418 		SENDCFGSTRLOC("erdriven");
   401 		SENDCFGSTRLOC(QString("ename team %1").arg(list[2]));
   419 		SENDCFGSTRLOC(QString("ename team %1").arg(list[1]));
   402 		for (int i = 0; i < 8; i++)
   420 		for (int i = 0; i < 8; i++)
   403 		{
   421 		{
   404 			SENDCFGSTRLOC(QString("ename hh%1").arg(i) + list[i + 3]);
   422 			SENDCFGSTRLOC(QString("ename hh%1 ").arg(i) + list[i + 2]);
   405 		}
   423 		}
   406 chkp;	}
   424 	}
   407 }
   425 }
   408 
   426 
   409 void HWNet::AddTeam(const HWTeam & team)
   427 void HWNet::AddTeam(const HWTeam & team)
   410 {
   428 {
   411 	if (state != nsJoined)
   429 	if (state != nsJoined)