-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswPhysCreateMsg.cpp
39 lines (33 loc) · 1.23 KB
/
swPhysCreateMsg.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
#include "swPhysCreateMsg.h"
#include "swFactory.h"
#include "swShip.h"
swPhysCreateMsg::swPhysCreateMsg() : object(NULL) {
type = SW_PHYS_CREATE_MSG;
}
swPhysCreateMsg::~swPhysCreateMsg() {}
void swPhysCreateMsg::write(swStream* stream) {
swFactory::writeObject(object, stream);
}
void swPhysCreateMsg::read(swStream* stream) {
object = swFactory::readPhysical(stream);
}
void swPhysCreateMsg::cliHandle(swClient* client) {
// add the received object to the simulator
client->game->simulator.insert(object, true);
// assign the object's owner, if it has one
if(object->ownerId != -1) {
object->owner = &client->players[object->ownerId];
// players need to receive their shipId when their ship is created
if(object->type == swObject::SW_SHIP)
object->owner->shipId = client->game->simulator.objects.indexOf(object);
}
// since it was added to this list, we don't need to delete it
}
void swPhysCreateMsg::servHandle(swServer* server, QTcpSocket* sock) {
// forward the message to all clients
foreach(QTcpSocket* sock, server->socks) {
swFactory::writeObject(this, sock);
}
// only the server needs to delete the object after sending
delete object;
}