63 LocalCFG(teams[index]); |
64 LocalCFG(teams[index]); |
64 } |
65 } |
65 |
66 |
66 void HWGame::SendConfig() |
67 void HWGame::SendConfig() |
67 { |
68 { |
68 SendIPC(QString("eseed %1").arg(seed)); |
69 SendIPC(QString("eseed %1").arg(seed).toAscii()); |
69 SendIPC(QString("etheme %1").arg(config->GetRandomTheme())); |
70 SendIPC(QString("etheme %1").arg(config->GetRandomTheme()).toAscii()); |
70 SENDIPC("TL"); |
71 SendIPC("TL"); |
71 SendIPC(QString("e$gmflags %1").arg(gamecfg->getGameFlags())); |
72 SendIPC(QString("e$gmflags %1").arg(gamecfg->getGameFlags()).toAscii()); |
72 |
73 |
73 for (int i = 0; i < TeamCount; i++) |
74 for (int i = 0; i < TeamCount; i++) |
74 { |
75 { |
75 SENDIPC("eaddteam"); |
76 SendIPC("eaddteam"); |
76 LocalCFG(teams[i]); |
77 LocalCFG(teams[i]); |
77 SendIPC(QString("ecolor %1").arg(65535 << i * 8)); |
78 SendIPC(QString("ecolor %1").arg(65535 << i * 8).toAscii()); |
78 for (int t = 0; t < hdNum[teams[i]]; t++) |
79 for (int t = 0; t < hdNum[teams[i]]; t++) |
79 SendIPC(QString("eadd hh%1 0").arg(t)); |
80 SendIPC(QString("eadd hh%1 0").arg(t).toAscii()); |
80 } |
81 } |
81 } |
82 } |
82 |
83 |
83 void HWGame::SendQuickConfig() |
84 void HWGame::SendQuickConfig() |
84 { |
85 { |
85 SendIPC(QString("eseed %1").arg(seed)); |
86 SendIPC(QString("eseed %1").arg(seed).toAscii()); |
86 SendIPC(QString("etheme %1").arg(config->GetRandomTheme())); |
87 SendIPC(QString("etheme %1").arg(config->GetRandomTheme()).toAscii()); |
87 SENDIPC("TL"); |
88 SendIPC("TL"); |
88 SendIPC(QString("e$gmflags %1").arg(gamecfg->getGameFlags())); |
89 SendIPC(QString("e$gmflags %1").arg(gamecfg->getGameFlags()).toAscii()); |
89 SENDIPC("eaddteam"); |
90 SendIPC("eaddteam"); |
90 LocalCFG(0); |
91 LocalCFG(0); |
91 SENDIPC("ecolor 65535"); |
92 SendIPC("ecolor 65535"); |
92 SENDIPC("eadd hh0 0"); |
93 SendIPC("eadd hh0 0"); |
93 SENDIPC("eadd hh1 0"); |
94 SendIPC("eadd hh1 0"); |
94 SENDIPC("eadd hh2 0"); |
95 SendIPC("eadd hh2 0"); |
95 SENDIPC("eadd hh3 0"); |
96 SendIPC("eadd hh3 0"); |
96 SENDIPC("eaddteam"); |
97 SendIPC("eaddteam"); |
97 LocalCFG(2); |
98 LocalCFG(2); |
98 SENDIPC("ecolor 16776960"); |
99 SendIPC("ecolor 16776960"); |
99 SENDIPC("eadd hh0 1"); |
100 SendIPC("eadd hh0 1"); |
100 SENDIPC("eadd hh1 1"); |
101 SendIPC("eadd hh1 1"); |
101 SENDIPC("eadd hh2 1"); |
102 SendIPC("eadd hh2 1"); |
102 SENDIPC("eadd hh3 1"); |
103 SendIPC("eadd hh3 1"); |
103 } |
104 } |
104 |
105 |
105 void HWGame::ParseMessage(const QByteArray & msg) |
106 void HWGame::ParseMessage(const QByteArray & msg) |
106 { |
107 { |
107 switch(msg.data()[1]) { |
108 switch(msg.data()[1]) { |
108 case '?': { |
109 case '?': { |
109 if (gameType == gtNet) |
110 if (gameType == gtNet) |
110 emit SendNet(QByteArray("\x01""?")); |
111 emit SendNet(QByteArray("\x01""?")); |
111 else |
112 else |
112 SENDIPC("!"); |
113 SendIPC("!"); |
113 break; |
114 break; |
114 } |
115 } |
115 case 'C': { |
116 case 'C': { |
116 switch (gameType) { |
117 switch (gameType) { |
117 case gtLocal: { |
118 case gtLocal: { |
152 { |
153 { |
153 emit SendNet(msg); |
154 emit SendNet(msg); |
154 } |
155 } |
155 demo->append(msg); |
156 demo->append(msg); |
156 } |
157 } |
157 } |
|
158 } |
|
159 |
|
160 void HWGame::SendIPC(const char * msg, quint8 len) |
|
161 { |
|
162 SendIPC(QByteArray::fromRawData(msg, len)); |
|
163 } |
|
164 |
|
165 void HWGame::SendIPC(const QString & buf) |
|
166 { |
|
167 SendIPC(QByteArray().append(buf)); |
|
168 } |
|
169 |
|
170 void HWGame::SendIPC(const QByteArray & buf) |
|
171 { |
|
172 if (buf.size() > MAXMSGCHARS) return; |
|
173 quint8 len = buf.size(); |
|
174 RawSendIPC(QByteArray::fromRawData((char *)&len, 1) + buf); |
|
175 } |
|
176 |
|
177 void HWGame::RawSendIPC(const QByteArray & buf) |
|
178 { |
|
179 if (!IPCSocket) |
|
180 { |
|
181 toSendBuf += buf; |
|
182 } else |
|
183 { |
|
184 if (toSendBuf.size() > 0) |
|
185 { |
|
186 IPCSocket->write(toSendBuf); |
|
187 demo->append(toSendBuf); |
|
188 toSendBuf.clear(); |
|
189 } |
|
190 IPCSocket->write(buf); |
|
191 demo->append(buf); |
|
192 } |
158 } |
193 } |
159 } |
194 |
160 |
195 void HWGame::FromNet(const QByteArray & msg) |
161 void HWGame::FromNet(const QByteArray & msg) |
196 { |
162 { |