forked from Skarsnik/QUsb2snes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwsservercommands.cpp
662 lines (627 loc) · 23.8 KB
/
wsservercommands.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
/*
* Copyright (c) 2018 Sylvain "Skarsnik" Colinet.
*
* This file is part of the QUsb2Snes project.
* (see https://github.com/Skarsnik/QUsb2snes).
*
* QUsb2Snes is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QUsb2Snes is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QUsb2Snes. If not, see <https://www.gnu.org/licenses/>.
*/
#include "ipsparse.h"
#include "wsserver.h"
#include <QLoggingCategory>
#include <QSerialPortInfo>
#ifndef QUSB2SNES_NOGUI
#include <QApplication>
#else
#include <QCoreApplication>
#endif
bool WSServer::isFileCommand(USB2SnesWS::opcode opcode)
{
return (opcode == USB2SnesWS::GetFile || opcode == USB2SnesWS::PutFile || opcode == USB2SnesWS::List ||
opcode == USB2SnesWS::Rename || opcode == USB2SnesWS::MakeDir || opcode == USB2SnesWS::Rename ||
opcode == USB2SnesWS::Remove);
}
bool WSServer::isControlCommand(USB2SnesWS::opcode opcode)
{
return (opcode == USB2SnesWS::Boot || opcode == USB2SnesWS::Reset || opcode == USB2SnesWS::Menu);
}
#define sDebug() qCDebug(log_wsserver)
#define sInfo() qCInfo(log_wsserver)
#define CMD_TAKE_ONE_ARG(cmd) if (req->arguments.size() != 1) \
{ \
setError(ErrorType::CommandError, QString("%1 command take one argument").arg(cmd)); \
clientError(ws); \
return ; \
}
// TODO, need to delete req when async device list is done
void WSServer::executeServerRequest(MRequest* req)
{
QWebSocket* ws = req->owner;
sInfo() << "Executing server request : " << *req << "for" << wsInfos.value(ws).name;
switch (req->opcode)
{
case USB2SnesWS::DeviceList : {
if (numberOfAsyncFactory == 0) {
QStringList l = getDevicesList();
sendReply(ws, l);
} else {
pendingDeviceListWebsocket.append(ws);
pendingDeviceListRequests.append(req);
if (pendingDeviceListWebsocket.size() == 1)
asyncDeviceList();
}
break;
}
case USB2SnesWS::Attach : {
CMD_TAKE_ONE_ARG("Attach")
cmdAttach(req);
break;
}
case USB2SnesWS::AppVersion : {
if (wsInfos.value(ws).legacy)
sendReply(ws, "7.42.0");
else
sendReply(ws, "QUsb2Snes-" + qApp->applicationVersion());
break;
}
case USB2SnesWS::Name : {
CMD_TAKE_ONE_ARG("Name")
wsInfos[ws].name = req->arguments.at(0);
sendReplyV2(ws, wsInfos[ws].name);
break;
}
case USB2SnesWS::Close : {
ws->close();
cleanUpSocket(ws);
break;
}
default:
break;
}
if (req->opcode != USB2SnesWS::DeviceList)
{
sInfo() << "Server request " << *req << " executed in " << req->timeCreated.msecsTo(QTime::currentTime());
delete req;
}
}
void WSServer::executeRequest(MRequest *req)
{
ADevice* device = nullptr;
QWebSocket* ws = req->owner;
if (isValidUnAttached(req->opcode))
{
executeServerRequest(req);
return;
}
device = wsInfos.value(ws).attachedTo;
sInfo() << "Executing request : " << *req << "for" << wsInfos.value(ws).name;
if (wsInfos.value(ws).attached)
device = wsInfos.value(ws).attachedTo;
switch(req->opcode)
{
case USB2SnesWS::Info : {
device->infoCommand();
req->state = RequestState::WAITINGREPLY;
break;
}
/*
* Control commands
*/
case USB2SnesWS::Reset :
{
device->controlCommand(SD2Snes::opcode::RESET);
req->state = RequestState::WAITINGREPLY;
break;
}
case USB2SnesWS::Menu :
{
device->controlCommand(SD2Snes::opcode::MENU_RESET);
req->state = RequestState::WAITINGREPLY;
break;
}
case USB2SnesWS::Boot :
{
CMD_TAKE_ONE_ARG("Boot")
device->controlCommand(SD2Snes::opcode::BOOT, req->arguments.at(0).toLatin1());
req->state = RequestState::WAITINGREPLY;
break;
}
/*
* File commands
*/
case USB2SnesWS::List : {
CMD_TAKE_ONE_ARG("List")
device->fileCommand(SD2Snes::opcode::LS, req->arguments.at(0).toLatin1());
req->state = RequestState::WAITINGREPLY;
break;
}
case USB2SnesWS::GetFile : {
CMD_TAKE_ONE_ARG("GetFile")
connect(device, &ADevice::getDataReceived, this, &WSServer::onDeviceGetDataReceived, Qt::UniqueConnection);
connect(device, &ADevice::sizeGet, this, &WSServer::onDeviceSizeGet, Qt::UniqueConnection);
device->fileCommand(SD2Snes::opcode::GET, req->arguments.at(0).toLatin1());
req->state = RequestState::WAITINGREPLY;
break;
}
case USB2SnesWS::PutFile : {
if (req->arguments.size() != 2)
{
setError(ErrorType::CommandError, "PutFile command take 2 arguments (file1, SizeInHex)");
clientError(ws);
return ;
}
bool ok;
device->putFile(req->arguments.at(0).toLatin1(), req->arguments.at(1).toUInt(&ok, 16));
req->state = RequestState::WAITINGREPLY;
wsInfos[ws].commandState = ClientCommandState::WAITINGBDATAREPLY;
wsInfos[ws].currentPutSize = req->arguments.at(1).toUInt(&ok, 16);
break;
}
case USB2SnesWS::Rename : {
if (req->arguments.size() != 2)
{
setError(ErrorType::CommandError, "Rename command take 2 arguments (file1, file2)");
clientError(ws);
return ;
}
device->fileCommand(SD2Snes::opcode::MV, QVector<QByteArray>() << req->arguments.at(0).toLatin1()
<< req->arguments.at(1).toLatin1());
req->state = RequestState::WAITINGREPLY;
break;
}
case USB2SnesWS::Remove : {
CMD_TAKE_ONE_ARG("Remove")
device->fileCommand(SD2Snes::opcode::RM, req->arguments.at(0).toLatin1());
req->state = RequestState::WAITINGREPLY;
break;
}
case USB2SnesWS::MakeDir : {
CMD_TAKE_ONE_ARG("MakeDir")
device->fileCommand(SD2Snes::opcode::MKDIR, req->arguments.at(0).toLatin1());
req->state = RequestState::WAITINGREPLY;
break;
}
/*
* Address command
*/
case USB2SnesWS::GetAddress : {
if (req->arguments.size() < 2)
{
setError(ErrorType::CommandError, "GetAddress commands take at least 2 arguments (AddressInHex, SizeInHex)");
clientError(ws);
return ;
}
connect(device, &ADevice::getDataReceived, this, &WSServer::onDeviceGetDataReceived, Qt::UniqueConnection);
//connect(device, SIGNAL(sizeGet(uint)), this, SLOT(onDeviceSizeGet(uint)));
bool ok;
if (req->arguments.size() == 2)
{
if (req->arguments.at(1).toUInt(&ok, 16) == 0)
{
setError(ErrorType::CommandError, "GetAddress - trying to read 0 byte");
clientError(ws);
return ;
}
device->getAddrCommand(req->space, req->arguments.at(0).toUInt(&ok, 16), req->arguments.at(1).toUInt(&ok, 16));
} else {
QList<QPair<unsigned int, unsigned int> > pairs;
// NOTE a size > 255 is ignored by the original server
// When it should probably be an error, but the ZeldaHub software use it
// Let fallback of spliting the request when it's a legacy connection
bool split = false;
for (int i = 0; i < req->arguments.size(); i += 2)
{
unsigned usize = req->arguments.at(i + 1).toUInt(&ok, 16);
if (usize == 0)
{
setError(ErrorType::CommandError, "GetAddress - trying to read 0 byte");
clientError(ws);
return ;
}
if (usize > 255)
{
if (wsInfos.value(ws).legacy)
{
split = true;
} else {
setError(ErrorType::CommandError, "GetAddress - VGet with a size > 255");
clientError(ws);
return ;
}
}
pairs.append(QPair<unsigned int, unsigned int>(req->arguments.at(i).toUInt(&ok, 16), usize));
}
if (!split && device->hasVariaditeCommands())
{
QList<QPair<unsigned int, quint8>> translatedPairs;
for (auto mpair : pairs)
{
translatedPairs.append(QPair<unsigned int, quint8>(mpair.first, static_cast<quint8>(mpair.second)));
}
device->getAddrCommand(req->space, translatedPairs);
} else {
device->getAddrCommand(req->space, req->arguments.at(0).toUInt(&ok, 16), req->arguments.at(1).toUInt(&ok, 16));
for (int i = 1; i < pairs.size(); i++)
{
sDebug() << pairs.at(i);
MRequest* newReq = new MRequest();
newReq->owner = ws;
newReq->state = RequestState::NEW;
newReq->space = SD2Snes::space::SNES;
newReq->timeCreated = QTime::currentTime();
newReq->wasPending = false;
newReq->opcode = USB2SnesWS::GetAddress;
newReq->arguments.append(QString::number(pairs.at(i).first, 16));
newReq->arguments.append(QString::number(pairs.at(i).second, 16));
pendingRequests[device].insert(i - 1, newReq);
}
}
}
req->state = RequestState::WAITINGREPLY;
break;
}
case USB2SnesWS::PutAddress : {
if (req->arguments.size() < 2)
{
setError(ErrorType::CommandError, "PutAddress command take at least 2 arguments (AddressInHex, SizeInHex)");
clientError(ws);
return ;
}
bool ok;
unsigned int putSize = 0;
bool spliced = false;
// Basic usage of PutAddress
// FIXME add flags in VPUT
if (req->arguments.size() == 2)
{
putSize = req->arguments.at(1).toUInt(&ok, 16);
if (putSize == 0)
{
setError(ErrorType::CommandError, "PutAddress - trying to write 0 byte");
clientError(ws);
return ;
}
if (req->flags.isEmpty())
device->putAddrCommand(req->space, req->arguments.at(0).toUInt(&ok, 16), req->arguments.at(1).toUInt(&ok, 16));
else {
unsigned char flags = 0;
foreach(QString flag, req->flags)
{
flags |= static_cast<SD2Snes::server_flags>(flagsMetaEnum.keyToValue(qPrintable(flag)));
}
device->putAddrCommand(req->space, flags, req->arguments.at(0).toUInt(&ok, 16), req->arguments.at(1).toUInt(&ok, 16));
}
} else {
QList<QPair<unsigned int, quint8> > vputArgs;
for (int i = 0; i < req->arguments.size(); i += 2)
{
if (req->arguments.at(i + 1).toUInt(&ok, 16) == 0)
{
setError(ErrorType::CommandError, "PutAddress - trying to write 0 byte");
clientError(ws);
return ;
}
vputArgs.append(QPair<unsigned int, quint8>(req->arguments.at(i).toUInt(&ok, 16), req->arguments.at(i + 1).toUShort(&ok, 16)));
putSize += req->arguments.at(i + 1).toUShort(&ok, 16);
}
if (device->hasVariaditeCommands())
{
device->putAddrCommand(req->space, vputArgs);
} else { // Please don't use VPUT
sDebug() << "VPUT that get spliced";
//spliced = true;
device->putAddrCommand(req->space, vputArgs.at(0).first, vputArgs.at(0).second);
putSize = vputArgs.at(0).second;
unsigned int totalSize = putSize;
// We should probably handle incomplete queued data, but who mad
// people will not send all bytes at once.
vputArgs.removeFirst();
QListIterator<QPair<unsigned int, quint8> > argsIt(vputArgs);
int cpt = 0;
while (argsIt.hasNext())
{
auto pair = argsIt.next();
MRequest* newReq = new MRequest();
newReq->owner = ws;
newReq->state = RequestState::NEW;
newReq->space = SD2Snes::space::SNES;
newReq->timeCreated = QTime::currentTime();
newReq->wasPending = true;
newReq->opcode = USB2SnesWS::PutAddress;
newReq->arguments.append(QString::number(pair.first, 16));
newReq->arguments.append(QString::number(pair.second, 16));
totalSize += pair.second;
pendingRequests[device].insert(cpt, newReq);
cpt++;
}
if (!req->wasPending)
wsInfos[ws].expectedDataSize = totalSize;
}
}
req->state = RequestState::WAITINGREPLY;
wsInfos[ws].commandState = ClientCommandState::WAITINGBDATAREPLY;
//sDebug() << "Writing before cps :" << __func__ << wsInfos[ws].currentPutSize;
wsInfos[ws].currentPutSize = putSize;
if (wsInfos[ws].expectedDataSize == 0)
wsInfos[ws].expectedDataSize = putSize;
//sDebug() << "Writing after cps" << __func__ << wsInfos[ws].currentPutSize;
break;
}
/*
* PutIPS
*/
case USB2SnesWS::PutIPS : {
if (req->arguments.size() < 2)
{
setError(ErrorType::CommandError, "PutIPS command take at least 2 arguments (Name, SizeInHex)");
clientError(ws);
return ;
}
bool ok;
req->state = RequestState::WAITINGREPLY;
wsInfos[ws].commandState = ClientCommandState::WAITINGBDATAREPLY;
wsInfos[ws].ipsSize = req->arguments.at(1).toUInt(&ok, 16);
break;
}
default:
{
setError(ErrorType::ProtocolError, "Invalid command or non implemented");
clientError(ws);
}
}
// There are multiple case with pending put request
// 1A : this was the only request in queue -> send recvData
// 1B : this was the only request in queue, no data -> do nothing
// 1C : this was the only request in queue, missing data -> send recvData
// 2A : other pending request, all data are here -> send recvData
// 2B : other pending request, no data -> do nothing
// 2C : other pending request, missing data -> send recvData
/*
*
*/
if (req->wasPending && (req->opcode == USB2SnesWS::PutFile || req->opcode == USB2SnesWS::PutAddress))
{
wsInfos[ws].commandState = ClientCommandState::WAITINGBDATAREPLY;
if (wsInfos[ws].recvData.size() >= wsInfos[ws].currentPutSize) // This cover 1A and 2A
{ // Only imcomplete data can be for later requests if this is not empty
//sDebug() << "Pending 1A & 2A";
sDebug() << "We have ALL data for the queued command " << wsInfos[ws].expectedDataSize;
QByteArray toSend = wsInfos[ws].recvData.left(wsInfos[ws].currentPutSize);
wsInfos[ws].recvData.remove(0, wsInfos[ws].currentPutSize);
wsInfos[ws].expectedDataSize -= wsInfos[ws].currentPutSize;
wsInfos[ws].currentPutSize = 0;
device->writeData(toSend);
wsInfos[ws].commandState = ClientCommandState::WAITINGREPLY;
} else {
if (!wsInfos[ws].recvData.isEmpty() && wsInfos[ws].recvData.size() < wsInfos[ws].currentPutSize)
{
sDebug() << "We have SOME data for the queued command " << wsInfos[ws].expectedDataSize;
device->writeData(wsInfos[ws].recvData);
wsInfos[ws].expectedDataSize -= wsInfos[ws].recvData.size();
wsInfos[ws].currentPutSize -= wsInfos[ws].recvData.size();
wsInfos[ws].recvData.clear();
} else {
// Nothing;
}
}
}
sDebug() << "Request executed";
return ;
}
#undef CMD_TAKE_ONE_ARG
void WSServer::processDeviceCommandFinished(ADevice* device)
{
DeviceInfos& info = devicesInfos[device];
sDebug() << "Processing command finished" << info.currentCommand;
//sDebug() << "Wriging before cps : " << __func__ << wsInfos[info.currentWS].currentPutSize;
wsInfos[info.currentWS].currentPutSize = 0;
//sDebug() << "Wriging after cps :" << __func__ << wsInfos[info.currentWS].currentPutSize;
switch (info.currentCommand) {
case USB2SnesWS::Info :
{
USB2SnesInfo ifo = device->parseInfo(device->dataRead);
sendReply(info.currentWS, QStringList() << ifo.version << ifo.deviceName << ifo.romPlaying << ifo.flags);
break;
}
// FILE Command
case USB2SnesWS::List :
{
QList<ADevice::FileInfos> lfi = device->parseLSCommand(device->dataRead);
QStringList rep;
foreach(ADevice::FileInfos fi, lfi)
{
rep << QString::number(static_cast<quint32>(fi.type));
rep << fi.name;
}
sendReply(info.currentWS, rep);
break;
}
case USB2SnesWS::GetFile :
{
disconnect(device, SIGNAL(getDataReceived(QByteArray)), this, SLOT(onDeviceGetDataReceived(QByteArray)));
disconnect(device, SIGNAL(sizeGet(uint)), this, SLOT(onDeviceSizeGet(uint)));
break;
}
case USB2SnesWS::Rename :
case USB2SnesWS::Remove :
case USB2SnesWS::MakeDir :
case USB2SnesWS::PutFile :
case USB2SnesWS::PutAddress :
case USB2SnesWS::Menu :
case USB2SnesWS::Reset :
case USB2SnesWS::Boot :
{
sendReplyV2(info.currentWS, "");
break;
}
case USB2SnesWS::GetAddress :
{
disconnect(device, &ADevice::getDataReceived, this, &WSServer::onDeviceGetDataReceived);
//disconnect(device, SIGNAL(sizeGet(uint)), this, SLOT(onDeviceSizeGet(uint)));
break;
}
default:
{
sDebug() << "Error, command not found";
return;
}
}
currentRequests[device]->state = RequestState::DONE;
sInfo() << "Device request finished - " << *(currentRequests.value(device)) << "processed in " << currentRequests.value(device)->timeCreated.msecsTo(QTime::currentTime()) << " ms";
delete currentRequests[device];
currentRequests[device] = nullptr;
}
/*
* Attach stuff
*/
// This will be deprecated when all devicefactory are made async
QStringList WSServer::getDevicesList()
{
QStringList toret;
sDebug() << "Device List";
foreach (DeviceFactory* devFact, deviceFactories)
{
toret.append(devFact->listDevices());
}
return toret;
}
void WSServer::asyncDeviceList()
{
sDebug() << "Async device list";
deviceList.clear();
pendingDeviceListQuery = 0;
for (auto devFact : qAsConst(deviceFactories))
{
if (!devFact->hasAsyncListDevices())
{
deviceList.append(devFact->listDevices());
}
}
for (auto devFact : qAsConst(deviceFactories))
{
if (devFact->hasAsyncListDevices())
{
if (devFact->asyncListDevices())
pendingDeviceListQuery++;
}
}
}
void WSServer::onDeviceListDone()
{
sDebug() << qobject_cast<DeviceFactory*>(sender())->name() << " is done doing devicelist";
pendingDeviceListQuery--;
if (pendingDeviceListQuery != 0)
return;
for (auto ws : qAsConst(pendingDeviceListWebsocket))
{
sDebug() << "Sending device list to " << wsInfos[ws].name;
sendReply(ws, deviceList);
}
for (MRequest* req : qAsConst(pendingDeviceListRequests))
{
sInfo() << "Device request finished - " << *req << "processed in " << req->timeCreated.msecsTo(QTime::currentTime()) << " ms";
delete req;
}
pendingDeviceListQuery = 0;
deviceList.clear();
pendingDeviceListRequests.clear();
pendingDeviceListWebsocket.clear();
}
void WSServer::onNewDeviceName(QString name)
{
sDebug() << "Received a device name : " << name;
deviceList.append(name);
}
void WSServer::cmdAttach(MRequest *req)
{
QString deviceToAttach = req->arguments.at(0);
wsInfos[req->owner].pendingAttach = true;
ADevice* devGet = nullptr;
foreach (DeviceFactory* devFact, deviceFactories)
{
sDebug() << devFact->name();
devGet = devFact->attach(deviceToAttach);
if (devGet != nullptr)
{
mapDevFact[devGet] = devFact;
break;
}
if (!devFact->attachError().isEmpty())
{
setError(ErrorType::CommandError, "Attach Error with " + deviceToAttach + " - " + devFact->attachError());
clientError(req->owner);
return ;
}
}
if (devGet != nullptr)
{
sDebug() << "Found device" << devGet->name() << "from" << mapDevFact[devGet]->name() << "State : " << devGet->state();
sDebug() << "Attaching " << wsInfos.value(req->owner).name << " to " << deviceToAttach;
if (devGet->state() == ADevice::State::CLOSED)
{
sDebug() << "Trying to open device";
if (!devGet->open())
{
setError(ErrorType::CommandError, "Attach: Can't open the device on " + deviceToAttach);
clientError(req->owner);
return;
}
}
if (!devices.contains(devGet))
addDevice(devGet);
wsInfos[req->owner].attached = true;
wsInfos[req->owner].attachedTo = devGet;
wsInfos[req->owner].pendingAttach = false;
sendReplyV2(req->owner, devGet->name());
if (devGet->state() == ADevice::READY)
processCommandQueue(devGet);
return ;
} else {
setError(ErrorType::CommandError, "Trying to Attach to an unknow device");
clientError(req->owner);
return ;
}
}
void WSServer::processIpsData(QWebSocket* ws)
{
sDebug() << "processing IPS data";
WSInfos& infos = wsInfos[ws];
MRequest* ipsReq = currentRequests[infos.attachedTo];
QList<IPSReccord> ipsReccords = parseIPSData(infos.ipsData);
// Creating new PutAddress requests
int cpt = 0;
sDebug() << "Creating " << ipsReccords.size() << "PutRequests";
foreach(IPSReccord ipsr, ipsReccords)
{
MRequest* newReq = new MRequest();
newReq->owner = ws;
newReq->state = RequestState::NEW;
newReq->space = SD2Snes::space::SNES;
newReq->timeCreated = QTime::currentTime();
newReq->wasPending = false;
newReq->opcode = USB2SnesWS::PutAddress;
// Special stuff for patch that install stuff in the NMI of sd2snes
if (cpt == 0 && ipsReq->arguments.at(0) == "hook")
newReq->flags << "CLRX";
if (cpt == (ipsReccords.size() - 1) && ipsReq->arguments.at(0) == "hook")
newReq->flags << "SETX";
newReq->arguments << QString::number(ipsr.offset, 16) << QString::number(ipsr.size, 16);
pendingRequests[infos.attachedTo].append(newReq);
infos.recvData.append(ipsr.data);
//sDebug() << "IPS:" << QString::number(ipsr.offset, 16) << ipsr.data.toHex();
cpt++;
}
infos.ipsData.clear();
processCommandQueue(infos.attachedTo);
}