QTfrontend/game.cpp
changeset 55 e09f7c952a40
parent 52 ae2950c5465c
child 74 42257fee61ae
equal deleted inserted replaced
54:839fd258ae6f 55:e09f7c952a40
    82 	LocalCFG(teams[index]);
    82 	LocalCFG(teams[index]);
    83 }
    83 }
    84 
    84 
    85 void HWGame::SendConfig()
    85 void HWGame::SendConfig()
    86 {
    86 {
       
    87 	SendIPC(QString("eseed %1").arg(seed));
       
    88 	SendIPC(QString("etheme %1").arg(GetThemeBySeed()));
       
    89 	//SENDIPC("emap test");
    87 	SENDIPC("TL");
    90 	SENDIPC("TL");
    88 //	SENDIPC("e$gmflags 0");
    91 	SENDIPC("e$gmflags 0");
    89 	SENDIPC("eaddteam");
    92 	SENDIPC("eaddteam");
    90 	SendTeamConfig(0);
    93 	SendTeamConfig(0);
    91 	SENDIPC("ecolor 65535");
    94 	SENDIPC("ecolor 65535");
    92 	SENDIPC("eadd hh0 0");
    95 	SENDIPC("eadd hh0 0");
    93 	SENDIPC("eadd hh1 0");
    96 	SENDIPC("eadd hh1 0");
   162 void HWGame::SendIPC(const char * msg, quint8 len)
   165 void HWGame::SendIPC(const char * msg, quint8 len)
   163 {
   166 {
   164 	SendIPC(QByteArray::fromRawData(msg, len));
   167 	SendIPC(QByteArray::fromRawData(msg, len));
   165 }
   168 }
   166 
   169 
       
   170 void HWGame::SendIPC(const QString & buf)
       
   171 {
       
   172 	SendIPC(QByteArray().append(buf));
       
   173 }
       
   174 
   167 void HWGame::SendIPC(const QByteArray & buf)
   175 void HWGame::SendIPC(const QByteArray & buf)
   168 {
   176 {
   169 	if (buf.size() > MAXMSGCHARS) return;
   177 	if (buf.size() > MAXMSGCHARS) return;
   170 	quint8 len = buf.size();
   178 	quint8 len = buf.size();
   171 	RawSendIPC(QByteArray::fromRawData((char *)&len, 1) + buf);
   179 	RawSendIPC(QByteArray::fromRawData((char *)&len, 1) + buf);
   219 		QMessageBox::critical(0, tr("Error"),
   227 		QMessageBox::critical(0, tr("Error"),
   220 				tr("Unable to start the server: %1.")
   228 				tr("Unable to start the server: %1.")
   221 				.arg(IPCServer->errorString()));
   229 				.arg(IPCServer->errorString()));
   222 	}
   230 	}
   223 
   231 
       
   232 	demo = new QByteArray;
   224 	QProcess * process;
   233 	QProcess * process;
   225 	QStringList arguments;
   234 	QStringList arguments;
   226 	process = new QProcess;
   235 	process = new QProcess;
   227 	arguments << resolutions[0][vid_Resolution];
   236 	arguments << resolutions[0][vid_Resolution];
   228 	arguments << resolutions[1][vid_Resolution];
   237 	arguments << resolutions[1][vid_Resolution];
   229 	arguments << GetThemeBySeed();
   238 	arguments << "16";
   230 	arguments << "46631";
   239 	arguments << "46631";
   231 	arguments << seed;
       
   232 	arguments << (vid_Fullscreen ? "1" : "0");
   240 	arguments << (vid_Fullscreen ? "1" : "0");
       
   241 	arguments << "1";
   233 	process->start("./hwengine", arguments);
   242 	process->start("./hwengine", arguments);
   234 }
   243 }
   235 
   244 
   236 void HWGame::AddTeam(const QString & teamname)
   245 void HWGame::AddTeam(const QString & teamname)
   237 {
   246 {
   313 		toSendBuf.append(QByteArray((char *)&buf, readbytes));
   322 		toSendBuf.append(QByteArray((char *)&buf, readbytes));
   314 
   323 
   315 	} while (readbytes > 0);
   324 	} while (readbytes > 0);
   316 	demofile.close();
   325 	demofile.close();
   317 
   326 
   318 	// cut seed
       
   319 	quint32 index = toSendBuf.indexOf(10);
       
   320 	if ((index < 3) || (index > 20))
       
   321 	{
       
   322 		QMessageBox::critical(0,
       
   323 				tr("Error"),
       
   324 				tr("Corrupted demo file %1").arg(demofilename),
       
   325 				tr("Quit"));
       
   326 		return ;
       
   327 	}
       
   328 	seed = QString(toSendBuf.left(index++));
       
   329 	toSendBuf.remove(0, index);
       
   330 
       
   331 	toSendBuf = QByteArray::fromRawData("\x02TD", 3) + toSendBuf;
       
   332 	// run engine
   327 	// run engine
   333 	demo = new QByteArray;
       
   334 	Start();
   328 	Start();
   335 }
   329 }
   336 
   330 
   337 void HWGame::StartNet(const QString & netseed)
   331 void HWGame::StartNet(const QString & netseed)
   338 {
   332 {
   339 	gameType = gtNet;
   333 	gameType = gtNet;
   340 	seed = netseed;
   334 	seed = netseed;
   341 	demo = new QByteArray;
   335 	demo = new QByteArray;
   342 	demo->append(seed.toLocal8Bit());
       
   343 	demo->append(10);
       
   344 	Start();
   336 	Start();
   345 }
   337 }
   346 
   338 
   347 void HWGame::StartLocal()
   339 void HWGame::StartLocal()
   348 {
   340 {
   349 	gameType = gtLocal;
   341 	gameType = gtLocal;
   350 	if (TeamCount < 2) return;
   342 	if (TeamCount < 2) return;
   351 	seedgen.GenRNDStr(seed, 10);
   343 	seedgen.GenRNDStr(seed, 10);
   352 	demo = new QByteArray;
       
   353 	demo->append(seed.toLocal8Bit());
       
   354 	demo->append(10);
       
   355 	Start();
   344 	Start();
   356 }
   345 }
   357 
   346 
   358 void HWGame::LocalCFG(const QString & teamname)
   347 void HWGame::LocalCFG(const QString & teamname)
   359 {
   348 {