Initial commit

This commit is contained in:
WatermelonModders
2022-05-31 12:35:46 -04:00
commit fc5cb0c32c
4097 changed files with 447075 additions and 0 deletions
+87
View File
@@ -0,0 +1,87 @@
/*
hm_gameserver - hearthmod gameserver
Copyright (C) 2016 Filip Pancik
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <proto.h>
void alloptions_free(struct alloptions_s *a)
{
struct option_s *o, *del;
for(o = a->options; o != NULL; del = o, o = o->next, option_free(del));
free(a);
}
int alloptions_serialize(void *ao, char **dst, const char *maxdst)
{
int n = 0;
struct option_s *m;
struct alloptions_s *s;
char *start;
start = *dst;
s = ao;
write_byte(dst, maxdst, 8);
write_uint64(dst, maxdst, s->id);
for(m = s->options; m != NULL; m = m->next) {
write_byte(dst, maxdst, 18);
n = option_size(m);
write_uint(dst, maxdst, n);
option_serialize(m, dst, maxdst);
}
return (*dst - start);
}
int alloptions_size(struct alloptions_s *p)
{
int num = 0, n;
struct option_s *s;
num += 1;
num += sizeofu64(p->id);
for(s = p->options; s != NULL; s = s->next) {
num += 1;
n = option_size(s);
num += sizeofu32(n) + n;
}
return num;
}
void alloptions_dump(struct alloptions_s *a)
{
struct suboption_target_s *t;
struct suboption_s *m;
struct option_s *o;
hm_log(LOG_DEBUG, lg, "Dumping alloptions:");
hm_log(LOG_DEBUG, lg, "id: %lld", a->id);
for(o = a->options; o != NULL; o = o->next) {
hm_log(LOG_DEBUG, lg, "\tOption type: %lld", o->type);
for(m = o->mainoption; m != NULL; m = m->next) {
hm_log(LOG_DEBUG, lg, "\t\tMainoption id: %lld", m->id);
for(t = m->target; t != NULL; t = t->next) {
hm_log(LOG_DEBUG, lg, "\t\t\tTarget id: %lld", t->value);
}
}
assert(o->suboptions == NULL);
}
}
+31
View File
@@ -0,0 +1,31 @@
/*
hm_gameserver - hearthmod gameserver
Copyright (C) 2016 Filip Pancik
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <proto.h>
int bnet_size(struct powerhistory_player_s *player)
{
int size = 0;
if(player) {
size += 2;
size += sizeofu64(player->bnet_hi);
size += sizeofu64(player->bnet_lo);
}
return size;
}
+65
View File
@@ -0,0 +1,65 @@
/*
hm_gameserver - hearthmod gameserver
Copyright (C) 2016 Filip Pancik
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <proto.h>
void chooseentities_free(struct chooseentities_s *c)
{
struct chooseentities_ent_s *e, *del;
for(e = c->entity; e != NULL; del = e, e = e->next, free(del));
free(c);
}
void *chooseentities_deserialize(char **dst, const char *maxdst)
{
int n, i;
struct chooseentities_s *c;
struct chooseentities_ent_s *e;
c = malloc(sizeof(*c));
memset(c, 0, sizeof(*c));
n = read_byte(dst, maxdst);
if(n != 8) {
error();
}
c->id = read_uint64(dst, maxdst);
c->entity = NULL;
n = read_byte(dst, maxdst);
if(n != 18) {
return c;
}
c->nentity = read_uint(dst, maxdst);
if(c->nentity > 5 || c->nentity < 0) {
free(c);
return NULL;
}
for(i = 0; i < c->nentity && *dst < maxdst; i++) {
e = malloc(sizeof(*e));
e->entity = read_uint(dst, maxdst);
e->next = c->entity;
c->entity = e;
}
return c;
}
+69
View File
@@ -0,0 +1,69 @@
/*
hm_gameserver - hearthmod gameserver
Copyright (C) 2016 Filip Pancik
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <proto.h>
void chooseoption_free(struct chooseoption_s *c)
{
free(c);
}
void *chooseoption_deserialize(char **dst, const char *maxdst)
{
int n;
struct chooseoption_s *o;
o = malloc(sizeof(*o));
memset(o, 0, sizeof(*o));
n = read_byte(dst, maxdst);
if(n != 8) {
error();
}
o->id = read_uint64(dst, maxdst);
n = read_byte(dst, maxdst);
if(n != 16) {
error();
}
o->index = read_uint64(dst, maxdst);
n = read_byte(dst, maxdst);
if(n != 24) {
error();
}
o->target = read_uint64(dst, maxdst);
while(*dst < maxdst) {
n = read_byte(dst, maxdst);
if(n == 32) {
o->suboption = read_uint64(dst, maxdst);
} else if(n == 40) {
o->position = read_uint64(dst, maxdst);
} else {
error();
}
}
return o;
}
void chooseoption_dump(struct chooseoption_s *o, u64 local_held_card)
{
hm_log(LOG_ALERT, lg, "Choose options dump: option id: %lld index: %lld target: %lld suboption: %lld position: %lld local held card: %lld", o->id, o->index, o->target, o->suboption, o->position, local_held_card);
}
+109
View File
@@ -0,0 +1,109 @@
/*
hm_gameserver - hearthmod gameserver
Copyright (C) 2016 Filip Pancik
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <proto.h>
void creategame_free(struct powerhistory_creategame_s *c)
{
struct powerhistory_player_s *player, *del;
for(player = c->player; player != NULL; del = player, player = player->next, player_free(del));
free(c);
}
struct powerhistory_creategame_s *creategame_deserialize(char **dst, const char *maxdst)
{
int n, len;
struct powerhistory_creategame_s *t;
struct powerhistory_player_s *player;
t = malloc(sizeof(*t));
t->player = t->player_tail = NULL;
n = read_byte(dst, maxdst);
if(n != 10) {
error();
}
len = read_uint(dst, maxdst);
t->game_entity = game_entity_deserialize(dst, *dst + len);
while(*dst < maxdst) {
n = read_byte(dst, maxdst);
if(n != 18) {
error();
}
len = read_uint(dst, maxdst);
player = player_deserialize(dst, *dst + len);
player->next = NULL;
if(t->player == NULL && t->player_tail == NULL) {
t->player = player;
t->player_tail = player;
} else {
t->player_tail->next = player;
t->player_tail = player;
}
}
return t;
}
int creategame_size(struct powerhistory_creategame_s *cg)
{
struct powerhistory_player_s *p;
int num = 0;
int n;
if(cg) {
num += 1;
n = game_entity_size(cg->game_entity);
num += sizeofu32(n) + n;
for(p = cg->player; p != NULL; p = p->next) {
num += 1;
n = player_size(p);
num += sizeofu32(n) + n;
}
}
return num;
}
int creategame_serialize(struct powerhistory_creategame_s *cg, char **dst, const char *maxdst)
{
int n;
struct powerhistory_player_s *p;
write_byte(dst, maxdst, 10);
n = game_entity_size(cg->game_entity);
write_uint(dst, maxdst, n);
game_entity_serialize(cg->game_entity, dst, maxdst);
for(p = cg->player; p != NULL; p = p->next) {
write_byte(dst, maxdst, 18);
n = player_size(p);
write_uint(dst, maxdst, n);
player_serialize(p, dst, maxdst);
}
return 0;
}
+120
View File
@@ -0,0 +1,120 @@
/*
hm_gameserver - hearthmod gameserver
Copyright (C) 2016 Filip Pancik
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <proto.h>
#define MAP_PACKET_MAX 12
typedef int (*f)(void *c);
static struct packet_deserialize_s map_packet[MAP_PACKET_MAX] = {
{P_GETGAMESTATE, NULL, NULL, NULL},
{P_CHOOSEOPTION, chooseoption_deserialize, NULL, (f)chooseoption_free},
{P_TURNTIMER, NULL, turntimer_serialize, (f)turntimer_free},
{P_CHOOSEENTITIES, chooseentities_deserialize, NULL, (f)chooseentities_free},
{P_ALLOPTIONS, NULL, alloptions_serialize, (f)alloptions_free},
{P_ENTITYCHOICES, NULL, entitychoices_serialize, (f)entitychoices_free},
{P_GAMESETUP, NULL, gamesetup_serialize, (f)gamesetup_free},
{P_USERUI, userui_deserialize, userui_serialize, (f)userui_free},
{P_POWERHISTORY, powerhistory_deserialize, powerhistory_serialize, (f)powerhistory_free},
{P_HANDSHAKE, handshake_deserialize, NULL, (f)handshake_free},
{P_PING, NULL, NULL, NULL},
{P_PONG, NULL, NULL, NULL},
};
struct packet_s *deserialize(char **dst, const char *maxdst)
{
struct packet_s *p;
int i;
if(!(dst != NULL && *dst != NULL && *dst < maxdst)) {
return NULL;
}
p = malloc(sizeof(*p));
p->id = read_mem_int(dst, maxdst);
p->len = read_mem_int(dst, maxdst);
for(i = 0; i < MAP_PACKET_MAX; i++) {
if(map_packet[i].id == p->id) {
if(map_packet[i].deserialize) {
p->data = map_packet[i].deserialize(dst, maxdst);
assert(p->data);
}
return p;
}
}
free(p);
return NULL;
}
void packet_free(struct packet_s *p)
{
int i;
for(i = 0; i < MAP_PACKET_MAX; i++) {
if(map_packet[i].id == p->id) {
if(map_packet[i].free) {
map_packet[i].free(p->data);
}
free(p);
break;
}
}
}
int serialize(struct packet_s *p, char **dst, const char *maxdst)
{
int i, n = 0;
char *off_len;
write_mem_int(dst, maxdst, p->id);
off_len = *dst;
write_mem_int(dst, maxdst, 0); // make space for length
n += 2 * sizeof(int);
for(i = 0; i < MAP_PACKET_MAX; i++) {
if(map_packet[i].id == p->id) {
if(map_packet[i].serialize) {
n += map_packet[i].serialize(p->data, dst, maxdst);
}
write_mem_int(&off_len, maxdst, n - (2 * sizeof(int)));
return n;
}
}
return -1;
}
struct packet_s *packet_init(enum packet_e id, void *data)
{
struct packet_s *p;
p = malloc(sizeof(*p));
p->id = id;
p->data = data;
return p;
}
+119
View File
@@ -0,0 +1,119 @@
/*
hm_gameserver - hearthmod gameserver
Copyright (C) 2016 Filip Pancik
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <proto.h>
void entity_free(struct powerhistory_entity_s *e)
{
struct powerhistory_tag_s *tag, *del;
for(tag = e->tag; tag != NULL; del = tag, tag = tag->next, tag_free(del));
//free(e->name);
free(e);
}
struct powerhistory_entity_s *entity_deserialize(char **dst, const char *maxdst)
{
int n, len;
struct powerhistory_entity_s *p;
struct powerhistory_tag_s *t;
p = malloc(sizeof(*p));
p->tag = p->tag_tail = NULL;
n = read_byte(dst, maxdst);
if(n != 8) {
error();
}
p->entity = read_uint64(dst, maxdst);
n = read_byte(dst, maxdst);
if(n != 18) {
error();
}
p->name = read_bytes(dst, maxdst, &p->nname);
while(*dst < maxdst) {
n = read_byte(dst, maxdst);
len = read_uint(dst, maxdst);
if(n == 26) {
t = tag_deserialize(dst, *dst + len);
t->next = NULL;
if(p->tag == NULL && p->tag_tail == NULL) {
p->tag = t;
p->tag_tail = t;
} else {
p->tag_tail->next = t;
p->tag_tail = t;
}
} else {
error();
return NULL;
}
}
return p;
}
int entity_size(struct powerhistory_entity_s *ent)
{
int num = 0;
int ts;
struct powerhistory_tag_s *tag;
num += 2;
num += sizeofu64(ent->entity);
num += sizeofu32(ent->nname) + ent->nname;
for(tag = ent->tag; tag != NULL; tag = tag->next) {
num += 1;
ts = tag_size(tag);
num += sizeofu32(ts) + ts;
}
return num;
}
int entity_serialize(struct powerhistory_entity_s *ent, char **dst, const char *maxdst)
{
int ts;
struct powerhistory_tag_s *t;
write_byte(dst, maxdst, 8);
write_uint64(dst, maxdst, ent->entity);
write_byte(dst, maxdst, 18);
write_bytes(dst, maxdst, ent->name, ent->nname);
if(ent->tag) {
for(t = ent->tag; t != NULL; t = t->next) {
write_byte(dst, maxdst, 26);
ts = tag_size(t);
write_uint(dst, maxdst, ts);
tag_serialize(t, dst, maxdst);
}
}
return 0;
}
+89
View File
@@ -0,0 +1,89 @@
/*
hm_gameserver - hearthmod gameserver
Copyright (C) 2016 Filip Pancik
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <proto.h>
void entitychoices_free(struct entitychoices_s *ec)
{
struct entitychoices_entities_s *e, *del;
for(e = ec->entities; e != NULL; del = e, e = e->next, free(del));
free(ec);
}
int entitychoices_serialize(void *ep, char **dst, const char *maxdst)
{
int n = 0;
struct entitychoices_entities_s *es;
struct entitychoices_s *e = ep;
char *start;
start = *dst;
write_byte(dst, maxdst, 8);
write_uint64(dst, maxdst, e->id);
write_byte(dst, maxdst, 16);
write_uint64(dst, maxdst, e->type);
write_byte(dst, maxdst, 32);
write_uint64(dst, maxdst, e->countmin);
write_byte(dst, maxdst, 40);
write_uint64(dst, maxdst, e->countmax);
if(e->entities) {
write_byte(dst, maxdst, 50);
for(es = e->entities; es != NULL; es = es->next) {
n += sizeofu64(es->entity);
}
write_uint(dst, maxdst, n);
for(es = e->entities; es != NULL; es = es->next) {
write_uint64(dst, maxdst, es->entity);
}
}
if(e->source > 0) {
write_byte(dst, maxdst, 56);
write_uint64(dst, maxdst, e->source);
}
write_byte(dst, maxdst, 64);
write_uint64(dst, maxdst, e->player_id);
return (*dst - start);
}
void entitychoices_dump(struct entitychoices_s *es)
{
struct entitychoices_entities_s *ent;
hm_log(LOG_DEBUG, lg, "Entity Choices dump:");
hm_log(LOG_DEBUG, lg, "\t\tID: %lld", es->id);
hm_log(LOG_DEBUG, lg, "\t\tType: %lld", es->type);
hm_log(LOG_DEBUG, lg, "\t\tCountMin: %lld", es->countmin);
hm_log(LOG_DEBUG, lg, "\t\tCountMax: %lld", es->countmax);
hm_log(LOG_DEBUG, lg, "\t\tSource: %lld", es->source);
hm_log(LOG_DEBUG, lg, "\t\tPlayer: %lld", es->player_id);
for(ent = es->entities; ent != NULL; ent = ent->next) {
hm_log(LOG_DEBUG, lg, "\t\t\tChild entity: %lld", ent->entity);
}
}
+105
View File
@@ -0,0 +1,105 @@
/*
hm_gameserver - hearthmod gameserver
Copyright (C) 2016 Filip Pancik
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <proto.h>
void game_entity_free(struct powerhistory_game_entity_s *g)
{
struct powerhistory_tag_s *tag, *del;
for(tag = g->tag; tag != NULL; del = tag, tag = tag->next, tag_free(del));
free(g);
}
struct powerhistory_game_entity_s *game_entity_deserialize(char **dst, const char *maxdst)
{
int n, len;
struct powerhistory_game_entity_s *t;
struct powerhistory_tag_s *tag;
t = malloc(sizeof(*t));
memset(t, 0, sizeof(*t));
n = read_byte(dst, maxdst);
if(n != 8) {
error();
}
t->id = read_uint64(dst, maxdst);
while(*dst < maxdst) {
n = read_byte(dst, maxdst);
if(n != 18) {
error();
}
len = read_uint(dst, maxdst);
tag = tag_deserialize(dst, *dst + len);
tag->next = NULL;
if(t->tag == NULL && t->tag_tail == NULL) {
t->tag = tag;
t->tag_tail = tag;
} else {
t->tag_tail->next = tag;
t->tag_tail = tag;
}
}
return t;
}
int game_entity_serialize(struct powerhistory_game_entity_s *ent, char **dst, const char *maxdst)
{
int ts;
struct powerhistory_tag_s *t;
write_byte(dst, maxdst, 8);
write_uint64(dst, maxdst, ent->id);
if(ent->tag) {
for(t = ent->tag; t != NULL; t = t->next) {
write_byte(dst, maxdst, 18);
ts = tag_size(t);
write_uint(dst, maxdst, ts);
tag_serialize(t, dst, maxdst);
}
}
return 0;
}
int game_entity_size(struct powerhistory_game_entity_s *ent)
{
int ts;
struct powerhistory_tag_s *tag;
int num = 0;
num += 1;
num += sizeofu64(ent->id);
for(tag = ent->tag; tag != NULL; tag = tag->next) {
num += 1;
ts = tag_size(tag);
num += sizeofu32(ts) + ts;
}
return num;
}
+81
View File
@@ -0,0 +1,81 @@
/*
hm_gameserver - hearthmod gameserver
Copyright (C) 2016 Filip Pancik
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <proto.h>
void gamesetup_free(struct gamesetup_s *g)
{
free(g);
}
struct gamesetup_s *gamesetup_deserialize(char **dst, const char *maxdst)
{
abort();
return NULL;
}
int gamesetup_serialize(void *data, char **dst, const char *maxdst)
{
char *start;
struct gamesetup_s *g = data;
start = *dst;
write_byte(dst, maxdst, 8);
write_uint64(dst, maxdst, g->board);
write_byte(dst, maxdst, 16);
write_uint64(dst, maxdst, g->maxsecrets);
write_byte(dst, maxdst, 24);
write_uint64(dst, maxdst, g->maxfriendlyminions);
if(g->keepalive > 0) {
write_byte(dst, maxdst, 32);
write_uint64(dst, maxdst, g->keepalive);
}
if(g->stuckdisconnect > 0) {
write_byte(dst, maxdst, 40);
write_uint64(dst, maxdst, g->stuckdisconnect);
}
return (*dst - start);
}
int gamesetup_size(struct gamesetup_s *g)
{
int num = 0;
num += 3;
num += sizeofu64(g->board);
num += sizeofu64(g->maxsecrets);
num += sizeofu64(g->maxfriendlyminions);
if(g->keepalive > 0) {
num += 1;
num += sizeofu64(g->keepalive);
}
if(g->stuckdisconnect > 0) {
num += 1;
num += sizeofu64(g->stuckdisconnect);
}
return num;
}
+83
View File
@@ -0,0 +1,83 @@
/*
hm_gameserver - hearthmod gameserver
Copyright (C) 2016 Filip Pancik
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <proto.h>
void handshake_free(struct handshake_s *h)
{
platform_free(h->platform);
free(h->version);
free(h->password);
free(h);
}
void *handshake_deserialize(char **dst, const char *maxdst)
{
int n, len;
struct handshake_s *h;
h = malloc(sizeof(*h));
n = read_byte(dst, maxdst);
if(n != 8) {
error();
}
h->gamehandle = read_uint64(dst, maxdst);
n = read_byte(dst, maxdst);
if(n != 18) {
error();
}
h->password = read_bytes(dst, maxdst, &h->npassword);
n = read_byte(dst, maxdst);
if(n != 24) {
error();
}
h->clienthandle = read_uint64(dst, maxdst);
n = read_byte(dst, maxdst);
if(n == 32) {
h->mission = read_uint64(dst, maxdst);
n = read_byte(dst, maxdst);
}
if(n != 42) {
error();
}
h->version = read_bytes(dst, maxdst, &h->nversion);
n = read_byte(dst, maxdst);
if(n != 58) {
error();
}
len = read_uint(dst, maxdst);
h->platform = platform_deserialize(dst, *dst + len);
return h;
}
void handshake_dump(struct handshake_s *h)
{
hm_log(LOG_DEBUG, lg, "Gamehandle: %lld password: [%.*s] clienthandle: %lld mission: %lld verion: [%.*s] ", h->gamehandle, h->npassword, h->password, h->clienthandle, h->mission, h->nversion, h->version);
if(h->platform) {
hm_log(LOG_DEBUG, lg, "Os: %lld screen: %lld name: [%.*s] store: %lld", h->platform->os, h->platform->screen, h->platform->nname, h->platform->name, h->platform->store);
}
}
+69
View File
@@ -0,0 +1,69 @@
/*
hm_gameserver - hearthmod gameserver
Copyright (C) 2016 Filip Pancik
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <proto.h>
void hide_free(struct powerhistory_hide_s *t)
{
free(t);
}
struct powerhistory_hide_s *hide_deserialize(char **dst, const char *maxdst)
{
int n;
struct powerhistory_hide_s *t;
t = malloc(sizeof(*t));
n = read_byte(dst, maxdst);
if(n != 8) {
error();
}
t->entity = read_uint64(dst, maxdst);
n = read_byte(dst, maxdst);
if(n != 16) {
error();
}
t->zone = read_uint64(dst, maxdst);
return t;
}
int hide_serialize(struct powerhistory_hide_s *ent, char **dst, const char *maxdst)
{
write_byte(dst, maxdst, 8);
write_uint64(dst, maxdst, ent->entity);
write_byte(dst, maxdst, 16);
write_uint64(dst, maxdst, ent->zone);
return 0;
}
int hide_size(struct powerhistory_hide_s *hide)
{
int size = 0;
if(hide) {
size += 2;
size += sizeofu64(hide->entity);
size += sizeofu64(hide->zone);
}
return size;
}
+126
View File
@@ -0,0 +1,126 @@
/*
hm_gameserver - hearthmod gameserver
Copyright (C) 2016 Filip Pancik
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <proto.h>
void meta_free(struct powerhistory_meta_s *t)
{
struct powerhistory_info_s *info, *del;
for(info = t->info; info != NULL; del = info, info = info->next, free(del));
free(t);
}
struct powerhistory_meta_s *meta_deserialize(char **dst, const char *maxdst)
{
int n, len;
struct powerhistory_meta_s *t;
struct powerhistory_info_s *info;
int i;
t = malloc(sizeof(*t));
memset(t, 0, sizeof(*t));
while(*dst < maxdst) {
n = read_byte(dst, maxdst);
if(n == 18) {
len = read_uint(dst, maxdst);
for(i = 0; i < len; i++) {
info = malloc(sizeof(*info));
info->id = read_uint64(dst, maxdst);
info->next = NULL;
if(t->info == NULL && t->info_tail == NULL) {
t->info = info;
t->info_tail = info;
} else {
t->info_tail->next = info;
t->info_tail = info;
}
}
} else if(n == 24) {
t->type = read_uint64(dst, maxdst);
} else if(n == 32) {
t->data = read_uint64(dst, maxdst);
} else {
error();
}
}
return t;
}
int meta_size(struct powerhistory_meta_s *p)
{
int num = 0, num2;
struct powerhistory_info_s *m;
if(p->info) {
num += 1;
num2 = num;
for(m = p->info; m != NULL; m = m->next) {
num += sizeofu64(m->id);
}
num += sizeofu32(num - num2);
}
if(p->type != 0) {
num += 1;
num += sizeofu64(p->type);
}
if(p->data != 0) {
num += 1;
num += sizeofu64(p->data);
}
return num;
}
int meta_serialize(struct powerhistory_meta_s *p, char **dst, const char *maxdst)
{
int num = 0;
struct powerhistory_info_s *m;
if(p->info) {
write_byte(dst, maxdst, 18);
for(m = p->info; m != NULL; m = m->next) {
num += sizeofu64(m->id);
}
write_uint(dst, maxdst, num);
for(m = p->info; m != NULL; m = m->next) {
write_uint64(dst, maxdst, m->id);
}
}
if(p->type != 0) {
write_byte(dst, maxdst, 24);
write_uint64(dst, maxdst, p->type);
}
if(p->data != 0) {
write_byte(dst, maxdst, 32);
write_uint64(dst, maxdst, p->data);
}
return 0;
}
+104
View File
@@ -0,0 +1,104 @@
/*
hm_gameserver - hearthmod gameserver
Copyright (C) 2016 Filip Pancik
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <proto.h>
void mouseinfo_free(struct mouseinfo_s *m)
{
free(m);
}
void *mouseinfo_deserialize(char **dst, const char *maxdst)
{
int n;
struct mouseinfo_s *c;
c = malloc(sizeof(*c));
memset(c, 0, sizeof(*c));
n = read_byte(dst, maxdst);
if(n != 8) {
error();
}
c->arroworigin = read_uint64(dst, maxdst);
n = read_byte(dst, maxdst);
if(n != 16) {
error();
}
c->heldcard = read_uint64(dst, maxdst);
n = read_byte(dst, maxdst);
if(n != 24) {
error();
}
c->overcard = read_uint64(dst, maxdst);
n = read_byte(dst, maxdst);
if(n != 32) {
error();
}
c->x = read_uint64(dst, maxdst);
n = read_byte(dst, maxdst);
if(n != 40) {
error();
}
c->y = read_uint64(dst, maxdst);
return c;
}
int mouseinfo_serialize(void *ao, char **dst, const char *maxdst)
{
struct mouseinfo_s *s;
char *start;
start = *dst;
s = ao;
write_byte(dst, maxdst, 8);
write_uint64(dst, maxdst, s->arroworigin);
write_byte(dst, maxdst, 16);
write_uint64(dst, maxdst, s->heldcard);
write_byte(dst, maxdst, 24);
write_uint64(dst, maxdst, s->overcard);
write_byte(dst, maxdst, 32);
write_uint64(dst, maxdst, s->x);
write_byte(dst, maxdst, 40);
write_uint64(dst, maxdst, s->y);
return (*dst - start);
}
int mouseinfo_size(struct mouseinfo_s *p)
{
int num = 0;
num += 5;
num += sizeofu64(p->arroworigin);
num += sizeofu64(p->heldcard);
num += sizeofu64(p->overcard);
num += sizeofu64(p->x);
num += sizeofu64(p->y);
return num;
}
+84
View File
@@ -0,0 +1,84 @@
/*
hm_gameserver - hearthmod gameserver
Copyright (C) 2016 Filip Pancik
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <proto.h>
void option_free(struct option_s *o)
{
struct suboption_s *s, *del;
for(s = o->mainoption; s != NULL; del = s, s = s->next, suboption_free(del));
for(s = o->suboptions; s != NULL; del = s, s = s->next, suboption_free(del));
free(o);
}
int option_serialize(struct option_s *s, char **dst, const char *maxdst)
{
int n = 0;
struct suboption_s *m;
char *start;
start = *dst;
write_byte(dst, maxdst, 8);
write_uint64(dst, maxdst, s->type);
if(s->mainoption) {
write_byte(dst, maxdst, 18);
n = suboption_size(s->mainoption);
write_uint(dst, maxdst, n);
suboption_serialize(s->mainoption, dst, maxdst);
}
if(s->suboptions) {
for(m = s->suboptions; m != NULL; m = m->next) {
write_byte(dst, maxdst, 26);
n = suboption_size(m);
write_uint(dst, maxdst, n);
suboption_serialize(m, dst, maxdst);
}
}
return (*dst - start);
}
int option_size(struct option_s *p)
{
int num = 0, n;
struct suboption_s *s;
num += 1;
num += sizeofu64(p->type);
if(p->mainoption) {
num += 1;
n = suboption_size(p->mainoption);
num += sizeofu32(n) + n;
}
if(p->suboptions) {
for(s = p->suboptions; s != NULL; s = s->next) {
num += 1;
n = suboption_size(s);
num += sizeofu32(n) + n;
}
}
return num;
}
+61
View File
@@ -0,0 +1,61 @@
/*
hm_gameserver - hearthmod gameserver
Copyright (C) 2016 Filip Pancik
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <proto.h>
void platform_free(struct platform_s *p)
{
free(p->name);
free(p);
}
struct platform_s *platform_deserialize(char **dst, const char *maxdst)
{
int n;
struct platform_s *h;
h = malloc(sizeof(*h));
h->store = 0;
n = read_byte(dst, maxdst);
if(n != 8) {
error();
}
h->os = read_uint64(dst, maxdst);
n = read_byte(dst, maxdst);
if(n != 16) {
error();
}
h->screen = read_uint64(dst, maxdst);
n = read_byte(dst, maxdst);
if(n != 26) {
error();
}
h->name = read_bytes(dst, maxdst, &h->nname);
if(*dst < maxdst) {
n = read_byte(dst, maxdst);
if(n == 32) {
h->store = read_uint64(dst, maxdst);
}
}
return h;
}
+116
View File
@@ -0,0 +1,116 @@
/*
hm_gameserver - hearthmod gameserver
Copyright (C) 2016 Filip Pancik
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <proto.h>
void player_free(struct powerhistory_player_s *p)
{
game_entity_free(p->entity);
free(p);
}
struct powerhistory_player_s *player_deserialize(char **dst, const char *maxdst)
{
int n, len;
struct powerhistory_player_s *player;
player = malloc(sizeof(*player));
n = read_byte(dst, maxdst);
if(n != 8) {
error();
}
player->id = read_uint64(dst, maxdst);
n = read_byte(dst, maxdst);
if(n != 18) {
error();
}
len = read_uint(dst, maxdst);
n = read_byte(dst, maxdst);
if(n != 8) {
error();
}
player->bnet_hi = read_uint64(dst, maxdst);
n = read_byte(dst, maxdst);
if(n != 16) {
error();
}
player->bnet_lo = read_uint64(dst, maxdst);
n = read_byte(dst, maxdst);
if(n != 24) {
error();
}
player->cardback = read_uint64(dst, maxdst);
n = read_byte(dst, maxdst);
if(n != 34) {
error();
}
len = read_uint(dst, maxdst);
player->entity = game_entity_deserialize(dst, *dst + len);
return player;
}
int player_serialize(struct powerhistory_player_s *player, char **dst, const char *maxdst)
{
int n;
write_byte(dst, maxdst, 8);
write_uint64(dst, maxdst, player->id);
// bnet
write_byte(dst, maxdst, 18);
n = bnet_size(player);
write_uint(dst, maxdst, n);
write_byte(dst, maxdst, 8);
write_uint64(dst, maxdst, player->bnet_hi);
write_byte(dst, maxdst, 16);
write_uint64(dst, maxdst, player->bnet_lo);
write_byte(dst, maxdst, 24);
write_uint64(dst, maxdst, player->cardback);
write_byte(dst, maxdst, 34);
n = game_entity_size(player->entity);
write_uint(dst, maxdst, n);
game_entity_serialize(player->entity, dst, maxdst);
return 0;
}
int player_size(struct powerhistory_player_s *p)
{
int size = 0, ts;
if(p) {
size += 4;
size += sizeofu64(p->id);
ts = bnet_size(p);
size += sizeofu32(ts) + ts;
size += sizeofu64(p->cardback);
ts = game_entity_size(p->entity);
size += sizeofu32(ts) + ts;
}
return size;
}
+42
View File
@@ -0,0 +1,42 @@
/*
hm_gameserver - hearthmod gameserver
Copyright (C) 2016 Filip Pancik
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <proto.h>
void powerend_free(struct powerhistory_powerend_s *p)
{
free(p);
}
struct powerhistory_powerend_s *powerend_deserialize(char **dst, const char *maxdst)
{
struct powerhistory_powerend_s *t;
t = malloc(sizeof(*t));
return t;
}
int powerend_serialize(struct powerhistory_powerend_s *t, char **dst, const char *maxdst)
{
return 0;
}
int powerend_size(struct powerhistory_powerend_s *p)
{
return 0;
}
+183
View File
@@ -0,0 +1,183 @@
/*
hm_gameserver - hearthmod gameserver
Copyright (C) 2016 Filip Pancik
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <proto.h>
void powerhistory_free(struct powerhistory_s *p)
{
struct powerhistory_data_s *d, *del;
for(d = p->data; d != NULL; del = d, d = d->next, powerhistory_data_free(del));
free(p);
}
void *powerhistory_deserialize(char **dst, const char *maxdst)
{
struct powerhistory_s *p;
struct powerhistory_data_s *d;
int n, len;
p = malloc(sizeof(*p));
p->data = NULL;
p->data_tail = NULL;
while(*dst < maxdst) {
n = read_byte(dst, maxdst);
len = read_uint(dst, maxdst);
if(n == 10) {
d = powerhistory_data_deserialize(dst, *dst + len);
d->next = NULL;
if(p->data == NULL && p->data_tail == NULL) {
p->data = d;
p->data_tail = d;
} else {
p->data_tail->next = d;
p->data_tail = d;
}
} else {
error();
return NULL;
}
}
return p;
}
int powerhistory_serialize(void *data, char **dst, const char *maxdst)
{
int n, o = 0;
struct powerhistory_data_s *d;
struct powerhistory_s *ph = data;
if(ph->data) {
for(d = ph->data; d != NULL; d = d->next) {
write_byte(dst, maxdst, 10);
o += 1;
n = powerhistorydata_size(d);
write_uint(dst, maxdst, n);
o += sizeofu32(n) + n;
powerhistorydata_serialize(d, dst, maxdst);
}
}
return o;
}
int powerhistory_size(struct powerhistory_s *ph)
{
struct powerhistory_data_s *d;
int n, num = 0;
if(ph->data) {
for(d = ph->data; d != NULL; d = d->next) {
num += 1;
n = powerhistorydata_size(d);
num += n + sizeofu32(n);
}
}
return num;
}
void powerhistory_dump(struct powerhistory_s *p)
{
struct powerhistory_tag_s *t;
struct powerhistory_data_s *d;
struct powerhistory_game_entity_s *ge;
struct powerhistory_player_s *player;
struct powerhistory_info_s *i;
int it = 0;
assert(p);
for(d = p->data; d != NULL; d = d->next) {
hm_log(LOG_DEBUG, lg, "Data %d", it++);
if(d->full) {
hm_log(LOG_DEBUG, lg, "data->full:");
hm_log(LOG_DEBUG, lg, "\tentity: %lld name: [%.*s]", d->full->entity, d->full->nname, d->full->name);
for(t = d->full->tag; t != NULL; t = t->next) {
hm_log(LOG_DEBUG, lg, "\t\ttag name: %lld value: %lld", t->name, t->value);
}
}
if(d->show) {
hm_log(LOG_DEBUG, lg, "data->show:");
hm_log(LOG_DEBUG, lg, "\tentity: %lld name: [%.*s]", d->show->entity, d->show->nname, d->show->name);
for(t = d->show->tag; t != NULL; t = t->next) {
hm_log(LOG_DEBUG, lg, "\t\ttag name: %lld value: %lld", t->name, t->value);
}
}
if(d->hide) {
hm_log(LOG_DEBUG, lg, "data->hide:");
hm_log(LOG_DEBUG, lg, "\tentity: %lld zone: %lld", d->hide->entity, d->hide->zone);
}
if(d->tagchange) {
hm_log(LOG_DEBUG, lg, "data->tagchange:");
hm_log(LOG_DEBUG, lg, "\tentity: %lld tag: %lld value: %lld", d->tagchange->entity, d->tagchange->tag, d->tagchange->value);
}
if(d->creategame) {
ge = d->creategame->game_entity;
hm_log(LOG_DEBUG, lg, "game entity id: %lld", ge->id);
for(t = ge->tag; t != NULL; t = t->next) {
hm_log(LOG_DEBUG, lg, "\ttag name: %lld value: %lld", t->name, t->value);
}
for(player = d->creategame->player; player != NULL; player = player->next) {
hm_log(LOG_DEBUG, lg, "\t\tdata->creategame->player:");
hm_log(LOG_DEBUG, lg, "\t\t\tid: %lld bhi: %lld blo: %lld cardback: %lld", player->id, player->bnet_hi, player->bnet_lo, player->cardback);
ge = player->entity;
hm_log(LOG_DEBUG, lg, "\t\t\tplayer->entity: %lld", ge->id);
for(t = ge->tag; t != NULL; t = t->next) {
hm_log(LOG_DEBUG, lg, "\t\t\t\ttag name: %lld value: %lld", t->name, t->value);
}
}
}
if(d->powerstart) {
hm_log(LOG_DEBUG, lg, "data->powerstart");
hm_log(LOG_DEBUG, lg, "\ttype: %lld index: %lld source: %lld target: %lld card: [%.*s]", d->powerstart->type, d->powerstart->index, d->powerstart->source, d->powerstart->target, d->powerstart->ncard_id, d->powerstart->card_id);
}
if(d->powerend) {
hm_log(LOG_DEBUG, lg, "data->powerend");
}
if(d->change_entity) {
hm_log(LOG_DEBUG, lg, "data->change_entity:");
hm_log(LOG_DEBUG, lg, "\tentity: %lld name: [%.*s]", d->change_entity->entity, d->change_entity->nname, d->change_entity->name);
for(t = d->change_entity->tag; t != NULL; t = t->next) {
hm_log(LOG_DEBUG, lg, "\t\ttag name: %lld value: %lld", t->name, t->value);
}
}
if(d->meta) {
hm_log(LOG_DEBUG, lg, "data->meta:");
hm_log(LOG_DEBUG, lg, "\ttype: %lld data: %lld", d->meta->type, d->meta->data);
for(i = d->meta->info; i != NULL; i = i->next) {
hm_log(LOG_DEBUG, lg, "\t\t\tinfo id: %lld", i->id);
}
}
}
}
+200
View File
@@ -0,0 +1,200 @@
/*
hm_gameserver - hearthmod gameserver
Copyright (C) 2016 Filip Pancik
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <proto.h>
void powerhistory_data_free(struct powerhistory_data_s *d)
{
if(d->full) entity_free(d->full);
if(d->show) entity_free(d->show);
if(d->hide) hide_free(d->hide);
if(d->tagchange) tagchange_free(d->tagchange);
if(d->creategame) creategame_free(d->creategame);
if(d->powerstart) powerstart_free(d->powerstart);
if(d->powerend) powerend_free(d->powerend);
if(d->change_entity) entity_free(d->change_entity);
if(d->meta) meta_free(d->meta);
free(d);
}
struct powerhistory_data_s *powerhistory_data_deserialize(char **dst, const char *maxdst)
{
struct powerhistory_data_s *p;
int n, len;
p = malloc(sizeof(*p));
memset(p, 0, sizeof(*p));
while(*dst < maxdst) {
n = read_byte(dst, maxdst);
len = read_uint(dst, maxdst);
if(n == 10) {
p->full = entity_deserialize(dst, *dst + len);
} else if(n == 18) {
p->show = entity_deserialize(dst, *dst + len);
} else if(n == 26) {
p->hide = hide_deserialize(dst, *dst + len);
} else if(n == 34) {
p->tagchange = tagchange_deserialize(dst, *dst + len);
} else if(n == 42) {
p->creategame = creategame_deserialize(dst, *dst + len);
} else if(n == 50) {
p->powerstart = powerstart_deserialize(dst, *dst + len);
} else if(n == 58) {
p->powerend = powerend_deserialize(dst, *dst + len);
} else if(n == 66) {
p->meta = meta_deserialize(dst, *dst + len);
} else {
return NULL;
}
}
return p;
}
int powerhistorydata_serialize(struct powerhistory_data_s *phd, char **dst, const char *maxdst)
{
int n;
if(phd->full) {
write_byte(dst, maxdst, 10);
n = entity_size(phd->full);
write_uint(dst, maxdst, n);
entity_serialize(phd->full, dst, maxdst);
}
if(phd->show) {
write_byte(dst, maxdst, 18);
n = entity_size(phd->show);
write_uint(dst, maxdst, n);
entity_serialize(phd->show, dst, maxdst);
}
if(phd->hide) {
write_byte(dst, maxdst, 26);
n = hide_size(phd->hide);
write_uint(dst, maxdst, n);
hide_serialize(phd->hide, dst, maxdst);
}
if(phd->tagchange) {
write_byte(dst, maxdst, 34);
n = tagchange_size(phd->tagchange);
write_uint(dst, maxdst, n);
tagchange_serialize(phd->tagchange, dst, maxdst);
}
if(phd->creategame) {
write_byte(dst, maxdst, 42);
n = creategame_size(phd->creategame);
write_uint(dst, maxdst, n);
creategame_serialize(phd->creategame, dst, maxdst);
}
if(phd->powerstart) {
write_byte(dst, maxdst, 50);
n = powerstart_size(phd->powerstart);
write_uint(dst, maxdst, n);
powerstart_serialize(phd->powerstart, dst, maxdst);
}
if(phd->powerend) {
write_byte(dst, maxdst, 58);
n = powerend_size(phd->powerend);
write_uint(dst, maxdst, n);
powerend_serialize(phd->powerend, dst, maxdst);
}
if(phd->meta) {
write_byte(dst, maxdst, 66);
n = meta_size(phd->meta);
write_uint(dst, maxdst, n);
meta_serialize(phd->meta, dst, maxdst);
}
if(phd->change_entity) {
write_byte(dst, maxdst, 74);
n = entity_size(phd->change_entity);
write_uint(dst, maxdst, n);
entity_serialize(phd->change_entity, dst, maxdst);
}
return 0;
}
int powerhistorydata_size(struct powerhistory_data_s *phd)
{
int num = 0, n;
if(phd->full) {
num += 1;
n = entity_size(phd->full);
num += n + sizeofu32(n);
}
if(phd->show) {
num += 1;
n = entity_size(phd->show);
num += n + sizeofu32(n);
}
if(phd->hide) {
num += 1;
n = hide_size(phd->hide);
num += n + sizeofu32(n);
}
if(phd->tagchange) {
num += 1;
n = tagchange_size(phd->tagchange);
num += n + sizeofu32(n);
}
if(phd->creategame) {
num += 1;
n = creategame_size(phd->creategame);
num += n + sizeofu32(n);
}
if(phd->powerstart) {
num += 1;
n = powerstart_size(phd->powerstart);
num += n + sizeofu32(n);
}
if(phd->powerend) {
num += 1;
n = powerend_size(phd->powerend);
num += n + sizeofu32(n);
}
if(phd->meta) {
num += 1;
n = meta_size(phd->meta);
num += n + sizeofu32(n);
}
if(phd->change_entity) {
num += 1;
n = entity_size(phd->change_entity);
num += n + sizeofu32(n);
}
return num;
}
+112
View File
@@ -0,0 +1,112 @@
/*
hm_gameserver - hearthmod gameserver
Copyright (C) 2016 Filip Pancik
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <proto.h>
void powerstart_free(struct powerhistory_powerstart_s *p)
{
free(p->card_id);
free(p);
}
struct powerhistory_powerstart_s *powerstart_deserialize(char **dst, const char *maxdst)
{
int n;
struct powerhistory_powerstart_s *t;
t = malloc(sizeof(*t));
n = read_byte(dst, maxdst);
if(n != 8) {
error();
}
t->type = read_uint64(dst, maxdst);
n = read_byte(dst, maxdst);
if(n != 16) {
error();
}
t->index = read_uint64(dst, maxdst);
n = read_byte(dst, maxdst);
if(n != 24) {
error();
}
t->source = read_uint64(dst, maxdst);
n = read_byte(dst, maxdst);
if(n != 32) {
error();
}
t->target = read_uint64(dst, maxdst);
t->ncard_id = 0;
t->card_id = NULL;
// optional
n = read_byte(dst, maxdst);
if(n != 42) {
return t;
}
t->card_id = read_bytes(dst, maxdst, &t->ncard_id);
return t;
}
int powerstart_serialize(struct powerhistory_powerstart_s *p, char **dst, const char *maxdst)
{
write_byte(dst, maxdst, 8);
write_uint64(dst, maxdst, p->type);
write_byte(dst, maxdst, 16);
write_uint64(dst, maxdst, p->index);
write_byte(dst, maxdst, 24);
write_uint64(dst, maxdst, p->source);
write_byte(dst, maxdst, 32);
write_uint64(dst, maxdst, p->target);
if(p->ncard_id > 0) {
write_byte(dst, maxdst, 42);
write_bytes(dst, maxdst, p->card_id, p->ncard_id);
}
return 0;
}
int powerstart_size(struct powerhistory_powerstart_s *p)
{
int size = 0;
int n;
if(p) {
size += 4;
size += sizeofu64(p->type);
size += sizeofu64(p->index);
size += sizeofu64(p->source);
size += sizeofu64(p->target);
if(p->ncard_id > 0) {
size += 1;
n = sizeofu64(p->ncard_id);
size += sizeofu32(n) + n;
}
}
return size;
}
+231
View File
@@ -0,0 +1,231 @@
/*
hm_gameserver - hearthmod gameserver
Copyright (C) 2016 Filip Pancik
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <proto.h>
int sizeofu64(u64 val)
{
unsigned int num = 1u;
while(1 == 1) {
val >>= 7;
if(val == 0) {
break;
}
num++;
}
return num;
}
int sizeofu32(int val)
{
unsigned int num = 1u;
while(1 == 1) {
val >>= 7;
if(val == 0) {
break;
}
num++;
}
return num;
}
int read_mem_int(char **dst, const char *end)
{
int n;
if(*dst + sizeof(int) > end) {
return -1;
}
n = *(int *)(*dst);
(*dst) += sizeof(int);
return n;
}
int write_mem_int(char **dst, const char *end, const int src)
{
if(*dst + sizeof(src) > end) {
hm_log(LOG_EMERG, lg, "Cannot write %d %p %p", src, *dst, end);
abort();
}
memcpy(*dst, &src, sizeof(src));
(*dst) += sizeof(src);
return 0;
}
int write_byte(char **dst, const char *end, char src)
{
if(*dst + sizeof(src) > end) {
hm_log(LOG_EMERG, lg, "Cannot write %d %p %p", src, *dst, end);
abort();
}
memcpy(*dst, &src, sizeof(src));
(*dst)++;
return 0;
}
char read_byte(char **dst, const char *end)
{
char out;
if(*dst + sizeof(char) > end) {
return -1;
}
out = *((char *)(*dst));
(*dst)++;
return out;
}
int skip(char **dst, const char *end, const int jump)
{
if((*dst + jump) > end) {
hm_log(LOG_ALERT, lg, "Invalid skip %p %p %d", *dst, end, jump);
return -1;
}
*dst += jump;
return 0;
}
int read_uint(char **dst, const char *end)
{
int num = 0, num2;
int i;
for(i = 0; (i < 5 && *dst < end); i++) {
num2 = read_byte(dst, end);
if(i == 4 && (num2 & 240) != 0) {
hm_log(LOG_EMERG, lg, "Incorrect num size");
abort();
}
if((num2 & 128) == 0) {
return num | (unsigned int)((unsigned int)num2 << 7 * i);
}
num |= (unsigned int)((unsigned int)(num2 & 127) << 7 * i);
}
return num;
}
u64 read_uint64(char **dst, const char *end)
{
u64 num = 0;
int num2;
int i;
for(i = 0; (i < 10 && *dst < end); i++) {
num2 = read_byte(dst, end);
if(i == 9 && (num2 & 254) != 0) {
hm_log(LOG_EMERG, lg, "Incorrect num size");
abort();
}
if((num2 & 128) == 0) {
return num | (unsigned long long)((unsigned long long)num2 << 7 * i);
}
num |= (unsigned long long)((unsigned long long)(num2 & 127) << 7 * i);
}
return num;
}
void write_uint(char **dst, const char *end, int src)
{
char b;
while(1 == 1) {
b = (char)(src & 127);
src >>= 7;
if(src == 0) {
break;
}
b |= 128;
write_byte(dst, end, b);
}
write_byte(dst, end, b);
}
char *read_bytes(char **dst, const char *end, int *ndst)
{
char *out;
*ndst = read_uint(dst, end);
if(*dst + *ndst > end) {
hm_log(LOG_EMERG, lg, "Dst read bytes %p %p %d", end, *dst + *ndst, *ndst);
abort();
}
out = malloc(*ndst);
memcpy(out, *dst, *ndst);
*dst += *ndst;
return out;
}
int write_bytes(char **dst, const char *end, const char *src, const int nsrc)
{
if(*dst + nsrc > end) {
hm_log(LOG_EMERG, lg, "Cannot write %d %p %p", nsrc, *dst, end);
abort();
}
write_uint(dst, end, nsrc);
memcpy(*dst, src, nsrc);
(*dst) += nsrc;
return 0;
}
void write_uint64(char **dst, const char *end, u64 src)
{
char b;
while(1 == 1) {
b = (char)(src & 127);
src >>= 7;
if(src == 0) {
break;
}
b |= 128;
write_byte(dst, end, b);
}
write_byte(dst, end, b);
}
+75
View File
@@ -0,0 +1,75 @@
/*
hm_gameserver - hearthmod gameserver
Copyright (C) 2016 Filip Pancik
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <proto.h>
void suboption_free(struct suboption_s *s)
{
struct suboption_target_s *t, *del;
for(t = s->target; t != NULL; del = t, t = t->next, free(del));
free(s);
}
int suboption_size(struct suboption_s *p)
{
int num = 0, num2;
struct suboption_target_s *m;
num += sizeofu64(p->id);
if(p->target) {
num += 1;
num2 = num;
for(m = p->target; m != NULL; m = m->next) {
num += sizeofu64(m->value);
}
num += sizeofu32(num - num2);
}
num += 1;
return num;
}
int suboption_serialize(struct suboption_s *s, char **dst, const char *maxdst)
{
int num = 0;
struct suboption_target_s *m;
char *start;
start = *dst;
write_byte(dst, maxdst, 8);
write_uint64(dst, maxdst, s->id);
if(s->target) {
write_byte(dst, maxdst, 26);
for(m = s->target; m != NULL; m = m->next) {
num += sizeofu64(m->value);
}
write_uint(dst, maxdst, num);
for(m = s->target; m != NULL; m = m->next) {
write_uint64(dst, maxdst, m->value);
}
}
return (*dst - start);
}
+73
View File
@@ -0,0 +1,73 @@
/*
hm_gameserver - hearthmod gameserver
Copyright (C) 2016 Filip Pancik
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <proto.h>
void tag_free(struct powerhistory_tag_s *t)
{
free(t);
}
struct powerhistory_tag_s *tag_deserialize(char **dst, const char *maxdst)
{
int n;
struct powerhistory_tag_s *t;
t = malloc(sizeof(*t));
n = read_byte(dst, maxdst);
if(n != 8) {
error();
}
t->name = read_uint64(dst, maxdst);
n = read_byte(dst, maxdst);
if(n != 16) {
error();
}
t->value = read_uint64(dst, maxdst);
return t;
}
int tag_size(struct powerhistory_tag_s *tag)
{
int size = 0;
if(tag) {
size += 2;
size += sizeofu64(tag->name);
size += sizeofu64(tag->value);
}
return size;
}
int tag_serialize(struct powerhistory_tag_s *t, char **dst, const char *maxdst)
{
write_byte(dst, maxdst, 8);
write_uint64(dst, maxdst, t->name);
write_byte(dst, maxdst, 16);
write_uint64(dst, maxdst, t->value);
return 0;
}
+79
View File
@@ -0,0 +1,79 @@
/*
hm_gameserver - hearthmod gameserver
Copyright (C) 2016 Filip Pancik
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <proto.h>
void tagchange_free(struct powerhistory_tagchange_s *t)
{
free(t);
}
struct powerhistory_tagchange_s *tagchange_deserialize(char **dst, const char *maxdst)
{
int n;
struct powerhistory_tagchange_s *t;
t = malloc(sizeof(*t));
n = read_byte(dst, maxdst);
if(n != 8) {
error();
}
t->entity = read_uint64(dst, maxdst);
n = read_byte(dst, maxdst);
if(n != 16) {
error();
}
t->tag = read_uint64(dst, maxdst);
n = read_byte(dst, maxdst);
if(n != 24) {
error();
}
t->value = read_uint64(dst, maxdst);
return t;
}
int tagchange_serialize(struct powerhistory_tagchange_s *ent, char **dst, const char *maxdst)
{
write_byte(dst, maxdst, 8);
write_uint64(dst, maxdst, ent->entity);
write_byte(dst, maxdst, 16);
write_uint64(dst, maxdst, ent->tag);
write_byte(dst, maxdst, 24);
write_uint64(dst, maxdst, ent->value);
return 0;
}
int tagchange_size(struct powerhistory_tagchange_s *t)
{
int size = 0;
if(t) {
size += 3;
size += sizeofu64(t->entity);
size += sizeofu64(t->tag);
size += sizeofu64(t->value);
}
return size;
}
+51
View File
@@ -0,0 +1,51 @@
/*
hm_gameserver - hearthmod gameserver
Copyright (C) 2016 Filip Pancik
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <proto.h>
void turntimer_free(struct turntimer_s *t)
{
free(t);
}
int turntimer_serialize(void *ao, char **dst, const char *maxdst)
{
struct turntimer_s *s;
char *start;
start = *dst;
s = ao;
write_byte(dst, maxdst, 8);
write_uint64(dst, maxdst, s->seconds);
write_byte(dst, maxdst, 16);
write_uint64(dst, maxdst, s->turn);
write_byte(dst, maxdst, 24);
write_byte(dst, maxdst, s->show);
return (*dst - start);
}
void turntimer_dump(struct turntimer_s *t)
{
hm_log(LOG_DEBUG, lg, "Turn timer dump:");
hm_log(LOG_DEBUG, lg, "\t\tseconds: %lld", t->seconds);
hm_log(LOG_DEBUG, lg, "\t\tturn: %lld", t->turn);
hm_log(LOG_DEBUG, lg, "\t\tshow: %d", t->show);
}
+124
View File
@@ -0,0 +1,124 @@
/*
hm_gameserver - hearthmod gameserver
Copyright (C) 2016 Filip Pancik
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <proto.h>
void userui_free(struct userui_s *u)
{
mouseinfo_free(u->mouseinfo);
free(u);
}
void *userui_deserialize(char **dst, const char *maxdst)
{
int n, len;
struct userui_s *c;
c = malloc(sizeof(*c));
memset(c, 0, sizeof(*c));
while(*dst < maxdst) {
n = read_byte(dst, maxdst);
if(n == 10) {
len = read_uint(dst, maxdst);
c->mouseinfo = mouseinfo_deserialize(dst, *dst + len);
}
else if(n == 16) {
c->emote = read_uint64(dst, maxdst);
}
else if(n == 24) {
c->player_id = read_uint64(dst, maxdst);
}
}
return c;
}
int userui_serialize(void *ao, char **dst, const char *maxdst)
{
struct userui_s *s;
char *start;
int n;
start = *dst;
s = ao;
if(s->mouseinfo) {
write_byte(dst, maxdst, 10);
n = mouseinfo_size(s->mouseinfo);
write_uint(dst, maxdst, n);
mouseinfo_serialize(s->mouseinfo, dst, maxdst);
}
if(s->emote != -1) {
write_byte(dst, maxdst, 16);
write_uint64(dst, maxdst, s->emote);
}
if(s->player_id != -1) {
write_byte(dst, maxdst, 24);
write_uint64(dst, maxdst, s->player_id);
}
return (*dst - start);
}
int userui_size(struct userui_s *p)
{
int num = 0, n;
if(p->mouseinfo) {
num += 1;
n = mouseinfo_size(p->mouseinfo);
num += n + sizeofu32(n);
}
if(p->emote != 0) {
num += 1;
num += sizeofu64(p->emote);
}
if(p->player_id != 0) {
num += 1;
num += sizeofu64(p->player_id);
}
return num;
}
void userui_dump(struct userui_s *u)
{
if(u) {
if(u->mouseinfo) {
hm_log(LOG_DEBUG, lg, "arrow origin: %lld", u->mouseinfo->arroworigin);
hm_log(LOG_DEBUG, lg, "heldcard: %lld", u->mouseinfo->heldcard);
hm_log(LOG_DEBUG, lg, "overcard: %lld", u->mouseinfo->overcard);
hm_log(LOG_DEBUG, lg, "x: %lld", u->mouseinfo->x);
hm_log(LOG_DEBUG, lg, "y: %lld", u->mouseinfo->y);
}
if(u->emote != 0) {
hm_log(LOG_DEBUG, lg, "emote: %lld", u->emote);
}
if(u->player_id != 0) {
hm_log(LOG_DEBUG, lg, "player_id: %lld", u->player_id);
}
}
}