QTfrontend/netclient.cpp
changeset 36 a803a00a3272
parent 32 78bff13b11c0
child 37 2b7f2a43b999
equal deleted inserted replaced
35:9367f246fb5f 36:a803a00a3272
   163 		if (msg == "AT8=")
   163 		if (msg == "AT8=")
   164 		{
   164 		{
   165 			// its ping ("?")
   165 			// its ping ("?")
   166 		} else
   166 		} else
   167 		{
   167 		{
   168 			RawSendNet(QString("PRIVMSG %1 :"MAGIC_CHAR MAGIC_CHAR"%2").arg(channel, msg));
   168 			if (state == nsGaming)
   169 		}
   169 			{
       
   170 				NetBuffer += buf;
       
   171 			} else
       
   172 			{
       
   173 				RawSendNet(QString("PRIVMSG %1 :"MAGIC_CHAR MAGIC_CHAR"%2").arg(channel, msg));
       
   174 			}
       
   175 		}
       
   176 	}
       
   177 }
       
   178 
       
   179 void HWNet::FlushNetBuf()
       
   180 {
       
   181 	if (NetBuffer.size() > 0)
       
   182 	{
       
   183 		RawSendNet(QString("PRIVMSG %1 :"MAGIC_CHAR MAGIC_CHAR"%2").arg(channel, QString(NetBuffer.toBase64())));
       
   184 		NetBuffer.clear();
   170 	}
   185 	}
   171 }
   186 }
   172 
   187 
   173 void HWNet::ParseLine(const QString & msg)
   188 void HWNet::ParseLine(const QString & msg)
   174 {
   189 {
   342 		{
   357 		{
   343 			QString msg;
   358 			QString msg;
   344 			msg = MAGIC_CHAR "T" MAGIC_CHAR + teams[i].nick + MAGIC_CHAR + teams[i].hhs.join(MAGIC_CHAR);
   359 			msg = MAGIC_CHAR "T" MAGIC_CHAR + teams[i].nick + MAGIC_CHAR + teams[i].hhs.join(MAGIC_CHAR);
   345 			RawSendNet(QString("PRIVMSG %1 :%2").arg(channel, msg));
   360 			RawSendNet(QString("PRIVMSG %1 :%2").arg(channel, msg));
   346 			hwp_chanmsg(mynick, msg);
   361 			hwp_chanmsg(mynick, msg);
   347 			SENDCFGSTRNET(QString("ecolor %1").arg(color));
   362 			QByteArray cache;
   348 			SENDCFGSTRNET("eadd hh0 0");
   363 			#define ADD(a) { \
   349 			SENDCFGSTRNET("eadd hh1 0");
   364 							QByteArray strmsg; \
   350 			SENDCFGSTRNET("eadd hh2 0");
   365 							strmsg.append(a); \
       
   366 							quint8 sz = strmsg.size(); \
       
   367 							cache.append(QByteArray((char *)&sz, 1)); \
       
   368 							cache.append(strmsg); \
       
   369 							}
       
   370 			ADD(QString("ecolor %1").arg(color));
       
   371 			ADD("eadd hh0 0");
       
   372 			ADD("eadd hh1 0");
       
   373 			ADD("eadd hh2 0");
       
   374 			ADD("eadd hh3 0");
       
   375 			ADD("eadd hh4 0");
       
   376 			#undef ADD
       
   377 			QString _msg = MAGIC_CHAR MAGIC_CHAR + QString(cache.toBase64());
       
   378 			hwp_chanmsg(mynick, _msg);
       
   379 			RawSendNet(QString("PRIVMSG %1 :").arg(channel) + _msg);
   351 			color <<= 8;
   380 			color <<= 8;
   352 		}
   381 		}
   353 		SENDCFGSTRNET("!");
   382 		SENDCFGSTRNET("!");
   354 		state = nsGaming;
       
   355 	}
   383 	}
   356 }
   384 }
   357 
   385 
   358 void HWNet::hwp_chanmsg(const QString & who, const QString & msg)
   386 void HWNet::hwp_chanmsg(const QString & who, const QString & msg)
   359 {
   387 {
   382 			return ;
   410 			return ;
   383 		}
   411 		}
   384 		if (msg == MAGIC_CHAR MAGIC_CHAR "ASE=")
   412 		if (msg == MAGIC_CHAR MAGIC_CHAR "ASE=")
   385 		{
   413 		{
   386 			state = nsGaming;
   414 			state = nsGaming;
       
   415 			TimerFlusher = new QTimer();
       
   416 			connect(TimerFlusher, SIGNAL(timeout()), this, SLOT(FlushNetBuf()));
       
   417 			TimerFlusher->start(2000);
   387 		}
   418 		}
   388 		if (msg.startsWith(MAGIC_CHAR"T"MAGIC_CHAR))
   419 		if (msg.startsWith(MAGIC_CHAR"T"MAGIC_CHAR))
   389 		{
   420 		{
   390 			NetTeamAdded(msg.mid(3));
   421 			NetTeamAdded(msg.mid(3));
   391 		}
   422 		}
   392 	}
   423 	}
   393 	if ((state != nsGaming) && (state != nsStarting))
   424 	if ((state < nsStarting) || (state > nsGaming))
   394 	{
   425 	{
   395 		return;
   426 		return;
   396 	}
   427 	}
   397 	if (msg.startsWith(MAGIC_CHAR MAGIC_CHAR)) // HWP message
   428 	if (msg.startsWith(MAGIC_CHAR MAGIC_CHAR)) // HWP message
   398 	{
   429 	{