QTfrontend/newnetclient.cpp
changeset 1311 49beb1221c0b
parent 1310 4616e15d566f
child 1313 f4c54e9e1b8c
equal deleted inserted replaced
1310:4616e15d566f 1311:49beb1221c0b
    49   NetSocket.connectToHost(hostName, port);
    49   NetSocket.connectToHost(hostName, port);
    50 }
    50 }
    51 
    51 
    52 void HWNewNet::Disconnect()
    52 void HWNewNet::Disconnect()
    53 {
    53 {
    54   m_game_connected=false;
    54   m_game_connected = false;
    55   NetSocket.disconnectFromHost();
    55   NetSocket.disconnectFromHost();
    56 }
    56 }
    57 
    57 
    58 void HWNewNet::CreateRoom(const QString & room)
    58 void HWNewNet::CreateRoom(const QString & room)
    59 {
    59 {
    65 	RawSendNet(QString("JOIN%1%2").arg(delimeter).arg(room));
    65 	RawSendNet(QString("JOIN%1%2").arg(delimeter).arg(room));
    66 }
    66 }
    67 
    67 
    68 void HWNewNet::AddTeam(const HWTeam & team)
    68 void HWNewNet::AddTeam(const HWTeam & team)
    69 {
    69 {
    70 	QString cmd = QString("ADDTEAM:") + delimeter +
    70 	QString cmd = QString("ADDTEAM") + delimeter +
    71 	     team.TeamName + delimeter +
    71 	     team.TeamName + delimeter +
    72 	     team.teamColor.name() + delimeter +
    72 	     team.teamColor.name() + delimeter +
    73 	     team.Grave + delimeter +
    73 	     team.Grave + delimeter +
    74 	     team.Fort + delimeter +
    74 	     team.Fort + delimeter +
    75 	     QString::number(team.difficulty);
    75 	     QString::number(team.difficulty);
    84 	RawSendNet(cmd);
    84 	RawSendNet(cmd);
    85 }
    85 }
    86 
    86 
    87 void HWNewNet::RemoveTeam(const HWTeam & team)
    87 void HWNewNet::RemoveTeam(const HWTeam & team)
    88 {
    88 {
    89   RawSendNet(QString("REMOVETEAM:") + delimeter + team.TeamName);
    89   RawSendNet(QString("REMOVETEAM") + delimeter + team.TeamName);
    90   m_networkToLocalteams.remove(m_networkToLocalteams.key(team.TeamName));
    90   m_networkToLocalteams.remove(m_networkToLocalteams.key(team.TeamName));
    91 }
    91 }
    92 
    92 
    93 void HWNewNet::StartGame()
    93 void HWNewNet::Ready()
    94 {
    94 {
    95   RawSendNet(QString("START:"));
    95   RawSendNet(QString("READY"));
    96 }
    96 }
    97 
    97 
    98 void HWNewNet::SendNet(const QByteArray & buf)
    98 void HWNewNet::SendNet(const QByteArray & buf)
    99 {
    99 {
   100   QString msg = QString(buf.toBase64());
   100   QString msg = QString(buf.toBase64());
   101 
   101 
   102   RawSendNet(QString("GAMEMSG:%1%2").arg(delimeter).arg(msg));
   102   RawSendNet(QString("GAMEMSG%1%2").arg(delimeter).arg(msg));
   103 }
   103 }
   104 
   104 
   105 void HWNewNet::RawSendNet(const QString & str)
   105 void HWNewNet::RawSendNet(const QString & str)
   106 {
   106 {
   107   RawSendNet(str.toUtf8());
   107   RawSendNet(str.toUtf8());
   191 	}
   191 	}
   192 
   192 
   193 	if (lst[0] == "CONNECTED") {
   193 	if (lst[0] == "CONNECTED") {
   194 		m_game_connected=true;
   194 		m_game_connected=true;
   195 		emit Connected();
   195 		emit Connected();
   196 		emit EnteredGame();
       
   197 		return;
   196 		return;
   198 	}
   197 	}
   199 
   198 
   200 	if (lst[0] == "CHAT_STRING") {
   199 	if (lst[0] == "CHAT_STRING") {
   201 		if(lst.size() < 3)
   200 		if(lst.size() < 3)
   241 		if(lst.size() < 2)
   240 		if(lst.size() < 2)
   242 		{
   241 		{
   243 			qWarning("Net: Bad JOINED message");
   242 			qWarning("Net: Bad JOINED message");
   244 			return;
   243 			return;
   245 		}
   244 		}
       
   245 		
   246 		for(int i = 1; i < lst.size(); ++i)
   246 		for(int i = 1; i < lst.size(); ++i)
       
   247 		{
       
   248 			if (lst[i] == mynick) emit EnteredGame();
   247 			emit nickAdded(lst[i]);
   249 			emit nickAdded(lst[i]);
       
   250 		}
   248 		return;
   251 		return;
   249 	}
   252 	}
   250 
   253 
   251 	if(lst[0]=="LEFT") {
   254 	if(lst[0]=="LEFT") {
   252 		if(lst.size() < 2)
   255 		if(lst.size() < 2)