mirror of
https://github.com/Oibaf66/frodo-wii.git
synced 2024-11-22 11:29:24 +01:00
Handle register data in marshal/demarshal and packet reception
This commit is contained in:
parent
6e3a5d74e0
commit
6b4014dfca
@ -682,6 +682,13 @@ bool Network::MarshalData(NetworkUpdate *p)
|
||||
NetworkUpdateSelectPeer *sp = (NetworkUpdateSelectPeer *)p->data;
|
||||
sp->server_id = htonl(sp->server_id);
|
||||
} break;
|
||||
case REGISTER_DATA:
|
||||
{
|
||||
NetworkUpdateRegisterData *ds = (NetworkUpdateRegisterData *)p->data;
|
||||
|
||||
ds->key = htonl(ds->key);
|
||||
ds->metadata = htonl(ds->metadata);
|
||||
} break;
|
||||
case LIST_PEERS:
|
||||
{
|
||||
NetworkUpdateListPeers *lp = (NetworkUpdateListPeers *)p->data;
|
||||
@ -696,6 +703,7 @@ bool Network::MarshalData(NetworkUpdate *p)
|
||||
peer->server_id = htonl(peer->server_id);
|
||||
peer->version = htonl(peer->version);
|
||||
peer->avatar = htonl(peer->avatar);
|
||||
peer->screenshot_key = htonl(peer->screenshot_key);
|
||||
}
|
||||
lp->n_peers = htonl(lp->n_peers);
|
||||
lp->your_port = htons(lp->your_port);
|
||||
@ -791,6 +799,13 @@ bool Network::DeMarshalData(NetworkUpdate *p)
|
||||
NetworkUpdateSelectPeer *sp = (NetworkUpdateSelectPeer *)p->data;
|
||||
sp->server_id = ntohl(sp->server_id);
|
||||
} break;
|
||||
case REGISTER_DATA:
|
||||
{
|
||||
NetworkUpdateRegisterData *ds = (NetworkUpdateRegisterData *)p->data;
|
||||
|
||||
ds->key = ntohl(ds->key);
|
||||
ds->metadata = ntohl(ds->metadata);
|
||||
} break;
|
||||
case LIST_PEERS:
|
||||
{
|
||||
NetworkUpdateListPeers *lp = (NetworkUpdateListPeers *)p->data;
|
||||
@ -807,6 +822,7 @@ bool Network::DeMarshalData(NetworkUpdate *p)
|
||||
peer->server_id = ntohl(peer->server_id);
|
||||
peer->version = ntohl(peer->version);
|
||||
peer->avatar = ntohl(peer->avatar);
|
||||
peer->screenshot_key = ntohl(peer->screenshot_key);
|
||||
}
|
||||
lp->your_port = ntohs(lp->your_port);
|
||||
} break;
|
||||
@ -922,6 +938,13 @@ bool Network::DecodeUpdate(C64Display *display, uint8 *js, MOS6581 *dst)
|
||||
case LIST_PEERS:
|
||||
{
|
||||
} break;
|
||||
case REGISTER_DATA:
|
||||
{
|
||||
NetworkUpdateRegisterData *rd = (NetworkUpdateRegisterData *)p->data;
|
||||
|
||||
DataStore::ds->registerNetworkData(rd->key, rd->metadata, rd->data,
|
||||
p->size - (sizeof(NetworkUpdateRegisterData) + sizeof(NetworkUpdate)));
|
||||
} break;
|
||||
case BANDWIDTH_PING:
|
||||
case PING:
|
||||
{
|
||||
|
@ -17,6 +17,20 @@ DataStore::~DataStore()
|
||||
free(this->registeredData);
|
||||
}
|
||||
|
||||
struct ds_data *DataStore::registerNetworkData(uint32_t key, uint32_t metadata,
|
||||
void *data, size_t data_sz)
|
||||
{
|
||||
struct ds_data *out;
|
||||
|
||||
out = (struct ds_data *)xmalloc(sizeof(struct ds_data) + data_sz);
|
||||
out->key = key;
|
||||
out->metadata = metadata;
|
||||
|
||||
memcpy(out->data, data, data_sz);
|
||||
|
||||
return this->registerData(key, out);
|
||||
}
|
||||
|
||||
struct ds_data *DataStore::registerData(uint32_t key,
|
||||
struct ds_data *data)
|
||||
{
|
||||
@ -49,6 +63,7 @@ struct ds_data *DataStore::registerData(uint32_t key,
|
||||
this->n_registeredData * sizeof(void*));
|
||||
}
|
||||
this->registeredData[i] = data;
|
||||
data->key = key;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -29,6 +29,9 @@ public:
|
||||
*/
|
||||
struct ds_data *registerData(uint32_t key, struct ds_data *data);
|
||||
|
||||
struct ds_data *registerNetworkData(uint32_t key, uint32_t metadata,
|
||||
void *data, size_t data_sz);
|
||||
|
||||
/**
|
||||
* Embed existing data into a data store. The new data is reallocated,
|
||||
* but the old is not freed
|
||||
|
Loading…
Reference in New Issue
Block a user