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;
}
+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 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);
}
int chooseentities_serialize(void *ao, char **dst, const char *maxdst)
{
struct chooseentities_s *s;
struct chooseentities_ent_s *e;
char *start;
start = *dst;
s = ao;
write_byte(dst, maxdst, 8);
write_uint64(dst, maxdst, s->id);
write_byte(dst, maxdst, 18);
write_uint64(dst, maxdst, s->nentity);
for(e = s->entity; e != NULL; e = e->next) {
write_uint(dst, maxdst, e->entity);
}
return (*dst - start);
}
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;
}
+99
View File
@@ -0,0 +1,99 @@
/*
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);
}
int chooseoption_serialize(void *ao, char **dst, const char *maxdst)
{
struct chooseoption_s *s;
char *start;
start = *dst;
s = ao;
write_byte(dst, maxdst, 8);
write_uint64(dst, maxdst, s->id);
write_byte(dst, maxdst, 16);
write_uint64(dst, maxdst, s->index);
write_byte(dst, maxdst, 24);
write_uint64(dst, maxdst, s->target);
if(s->suboption != 0) {
write_byte(dst, maxdst, 32);
write_uint64(dst, maxdst, s->suboption);
}
if(s->position != 0) {
write_byte(dst, maxdst, 40);
write_uint64(dst, maxdst, s->position);
}
return (*dst - start);
}
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_DEBUG, 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;
}
+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;
}
+144
View File
@@ -0,0 +1,144 @@
/*
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);
}
void *entitychoices_deserialize(char **dst, const char *maxdst)
{
int n, i;
struct entitychoices_s *o;
struct entitychoices_entities_s *e = e;
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->type = read_uint64(dst, maxdst);
n = read_byte(dst, maxdst);
if(n != 32) {
error();
}
o->countmin = read_uint64(dst, maxdst);
n = read_byte(dst, maxdst);
if(n != 40) {
error();
}
o->countmax = read_uint64(dst, maxdst);
while(*dst < maxdst) {
n = read_byte(dst, maxdst);
if(n == 50) {
int n = read_uint(dst, maxdst);
for(i = 0; i < n; i++) {
e = malloc(sizeof(*e));
e->entity = read_uint64(dst, maxdst);
e->next = o->entities;
o->entities = e;
}
} else if(n == 56) {
o->source = read_uint64(dst, maxdst);
} else if(n == 64) {
o->player_id = read_uint64(dst, maxdst);
} else {
error();
}
}
return o;
}
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;
}
+114
View File
@@ -0,0 +1,114 @@
/*
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);
}
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);
}
void *gamesetup_deserialize(char **dst, const char *maxdst)
{
int n;
struct gamesetup_s *o;
o = malloc(sizeof(*o));
memset(o, 0, sizeof(*o));
n = read_byte(dst, maxdst);
if(n != 8) {
error();
}
o->board = read_uint64(dst, maxdst);
n = read_byte(dst, maxdst);
if(n != 16) {
error();
}
o->maxsecrets = read_uint64(dst, maxdst);
n = read_byte(dst, maxdst);
if(n != 24) {
error();
}
o->maxfriendlyminions = read_uint64(dst, maxdst);
while(*dst < maxdst) {
n = read_byte(dst, maxdst);
if(n == 32) {
o->keepalive = read_uint64(dst, maxdst);
} else if(n == 40) {
o->stuckdisconnect = read_uint64(dst, maxdst);
} else {
error();
}
}
return o;
}
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;
}
+115
View File
@@ -0,0 +1,115 @@
/*
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);
}
int handshake_serialize(void *ao, char **dst, const char *maxdst)
{
struct handshake_s *s;
char *start;
start = *dst;
s = ao;
write_byte(dst, maxdst, 8);
write_uint64(dst, maxdst, s->gamehandle);
write_byte(dst, maxdst, 18);
write_bytes(dst, maxdst, s->password, s->npassword);
write_byte(dst, maxdst, 24);
write_uint64(dst, maxdst, s->clienthandle);
if(s->mission != 0) {
write_byte(dst, maxdst, 32);
write_uint64(dst, maxdst, s->mission);
}
write_byte(dst, maxdst, 42);
write_bytes(dst, maxdst, s->version, s->nversion);
write_byte(dst, maxdst, 58);
write_uint(dst, maxdst, platform_size(s->platform));
platform_serialize(s->platform, dst, maxdst);
return (*dst - start);
}
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;
}
+36
View File
@@ -0,0 +1,36 @@
/*
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/>.
*/
#ifndef CHOOSEENTITIES_H_
#define CHOOSEENTITIES_H_
struct chooseentities_ent_s {
u64 entity;
struct chooseentities_ent_s *next;
};
struct chooseentities_s {
u64 id;
int nentity;
struct chooseentities_ent_s *entity;
};
void chooseentities_free(struct chooseentities_s *c);
void *chooseentities_deserialize(char **dst, const char *maxdst);
int chooseentities_serialize(void *ao, char **dst, const char *maxdst);
#endif
+43
View File
@@ -0,0 +1,43 @@
/*
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/>.
*/
#ifndef ENTITYCHOICES_H_
#define ENTITYCHOICES_H_
struct entitychoices_entities_s {
u64 entity;
struct entitychoices_entities_s *next;
};
struct entitychoices_s {
u64 id;
u64 type;
u64 countmin;
u64 countmax;
u64 source;
u64 player_id;
struct entitychoices_entities_s *entities;
};
void entitychoices_free(struct entitychoices_s *ec);
int entitychoices_serialize(void *ep, char **dst, const char *maxdst);
void entitychoices_dump(struct entitychoices_s *es);
void *entitychoices_deserialize(char **dst, const char *maxdst);
#endif
+250
View File
@@ -0,0 +1,250 @@
/*
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/>.
*/
#ifndef TAG_H_
#define TAG_H_
enum gametag_e {
TAG_SCRIPT_DATA_NUM_1 = 2,
TAG_SCRIPT_DATA_NUM_2 = 3,
TAG_SCRIPT_DATA_ENT_1 = 4,
TAG_SCRIPT_DATA_ENT_2 = 5,
MISSION_EVENT = 6,
TIMEOUT = 7,
TURN_START = 8,
TURN_TIMER_SLUSH = 9,
PREMIUM = 12,
GOLD_REWARD_STATE = 13,
PLAYSTATE = 17,
LAST_AFFECTED_BY = 18,
STEP = 19,
TURN = 20,
FATIGUE = 22,
CURRENT_PLAYER = 23,
FIRST_PLAYER = 24,
RESOURCES_USED = 25,
RESOURCES = 26,
HERO_ENTITY = 27,
MAXHANDSIZE = 28,
STARTHANDSIZE = 29,
PLAYER_ID = 30,
TEAM_ID = 31,
TRIGGER_VISUAL = 32,
RECENTLY_ARRIVED = 33,
PROTECTING = 34,
PROTECTED = 35,
DEFENDING = 36,
PROPOSED_DEFENDER = 37,
ATTACKING = 38,
PROPOSED_ATTACKER = 39,
ATTACHED = 40,
EXHAUSTED = 43,
DAMAGE = 44,
HEALTH = 45,
ATK = 47,
COST = 48,
ZONE = 49,
CONTROLLER = 50,
OWNER = 51,
DEFINITION = 52,
ENTITY_ID = 53,
HISTORY_PROXY = 54,
COPY_DEATHRATTLE = 55,
ELITE = 114,
MAXRESOURCES = 176,
CARD_SET = 183,
CARDTEXT_INHAND = 184,
CARDNAME = 185,
CARD_ID = 186,
DURABILITY = 187,
SILENCED = 188,
WINDFURY = 189,
TAUNT = 190,
STEALTH = 191,
SPELLPOWER = 192,
DIVINE_SHIELD = 194,
CHARGE = 197,
NEXT_STEP = 198,
CLASS = 199,
CARDRACE = 200,
FACTION = 201,
CARDTYPE = 202,
RARITY = 203,
STATE = 204,
SUMMONED = 205,
FREEZE = 208,
ENRAGED = 212,
OVERLOAD = 215,
LOYALTY = 216,
DEATHRATTLE = 217,
BATTLECRY = 218,
SECRET = 219,
COMBO = 220,
CANT_HEAL = 221,
CANT_DAMAGE = 222,
CANT_SET_ASIDE = 223,
CANT_REMOVE_FROM_GAME = 224,
CANT_READY = 225,
CANT_EXHAUST = 226,
CANT_ATTACK = 227,
CANT_TARGET = 228,
CANT_DESTROY = 229,
CANT_DISCARD = 230,
CANT_PLAY = 231,
CANT_DRAW = 232,
INCOMING_HEALING_MULTIPLIER = 233,
INCOMING_HEALING_ADJUSTMENT = 234,
INCOMING_HEALING_CAP = 235,
INCOMING_DAMAGE_MULTIPLIER = 236,
INCOMING_DAMAGE_ADJUSTMENT = 237,
INCOMING_DAMAGE_CAP = 238,
CANT_BE_HEALED = 239,
CANT_BE_DAMAGED = 240,
CANT_BE_SET_ASIDE = 241,
CANT_BE_REMOVED_FROM_GAME = 242,
CANT_BE_READIED = 243,
CANT_BE_EXHAUSTED = 244,
CANT_BE_ATTACKED = 245,
CANT_BE_TARGETED = 246,
CANT_BE_DESTROYED = 247,
CANT_BE_SUMMONING_SICK = 253,
FROZEN = 260,
JUST_PLAYED = 261,
LINKEDCARD = 262,
ZONE_POSITION = 263,
CANT_BE_FROZEN = 264,
COMBO_ACTIVE = 266,
CARD_TARGET = 267,
NUM_CARDS_PLAYED_THIS_TURN = 269,
CANT_BE_TARGETED_BY_OPPONENTS = 270,
NUM_TURNS_IN_PLAY = 271,
NUM_TURNS_LEFT = 272,
OUTGOING_DAMAGE_CAP = 273,
OUTGOING_DAMAGE_ADJUSTMENT = 274,
OUTGOING_DAMAGE_MULTIPLIER = 275,
OUTGOING_HEALING_CAP = 276,
OUTGOING_HEALING_ADJUSTMENT = 277,
OUTGOING_HEALING_MULTIPLIER = 278,
INCOMING_ABILITY_DAMAGE_ADJUSTMENT = 279,
INCOMING_COMBAT_DAMAGE_ADJUSTMENT = 280,
OUTGOING_ABILITY_DAMAGE_ADJUSTMENT = 281,
OUTGOING_COMBAT_DAMAGE_ADJUSTMENT = 282,
OUTGOING_ABILITY_DAMAGE_MULTIPLIER = 283,
OUTGOING_ABILITY_DAMAGE_CAP = 284,
INCOMING_ABILITY_DAMAGE_MULTIPLIER = 285,
INCOMING_ABILITY_DAMAGE_CAP = 286,
OUTGOING_COMBAT_DAMAGE_MULTIPLIER = 287,
OUTGOING_COMBAT_DAMAGE_CAP = 288,
INCOMING_COMBAT_DAMAGE_MULTIPLIER = 289,
INCOMING_COMBAT_DAMAGE_CAP = 290,
CURRENT_SPELLPOWER = 291,
ARMOR = 292,
MORPH = 293,
IS_MORPHED = 294,
TEMP_RESOURCES = 295,
OVERLOAD_OWED = 296,
NUM_ATTACKS_THIS_TURN = 297,
NEXT_ALLY_BUFF = 302,
MAGNET = 303,
FIRST_CARD_PLAYED_THIS_TURN = 304,
MULLIGAN_STATE = 305,
TAUNT_READY = 306,
STEALTH_READY = 307,
CHARGE_READY = 308,
CANT_BE_TARGETED_BY_ABILITIES = 311,
SHOULDEXITCOMBAT = 312,
CREATOR = 313,
CANT_BE_DISPELLED = 314,
PARENT_CARD = 316,
NUM_MINIONS_PLAYED_THIS_TURN = 317,
PREDAMAGE = 318,
TARGETING_ARROW_TEXT = 325,
ENCHANTMENT_BIRTH_VISUAL = 330,
ENCHANTMENT_IDLE_VISUAL = 331,
CANT_BE_TARGETED_BY_HERO_POWERS = 332,
HEALTH_MINIMUM = 337,
TAG_ONE_TURN_EFFECT = 338,
SILENCE = 339,
COUNTER = 340,
ARTISTNAME = 342,
HAND_REVEALED = 348,
ADJACENT_BUFF = 350,
FLAVORTEXT = 351,
FORCED_PLAY = 352,
LOW_HEALTH_THRESHOLD = 353,
SPELLPOWER_DOUBLE = 356,
HEALING_DOUBLE = 357,
NUM_OPTIONS_PLAYED_THIS_TURN = 358,
TO_BE_DESTROYED = 360,
AURA = 362,
POISONOUS = 363,
HOW_TO_EARN = 364,
HOW_TO_EARN_GOLDEN = 365,
HERO_POWER_DOUBLE = 366,
AI_MUST_PLAY = 367,
NUM_MINIONS_PLAYER_KILLED_THIS_TURN = 368,
NUM_MINIONS_KILLED_THIS_TURN = 369,
AFFECTED_BY_SPELL_POWER = 370,
EXTRA_DEATHRATTLES = 371,
START_WITH_1_HEALTH = 372,
IMMUNE_WHILE_ATTACKING = 373,
MULTIPLY_HERO_DAMAGE = 374,
MULTIPLY_BUFF_VALUE = 375,
CUSTOM_KEYWORD_EFFECT = 376,
TOPDECK = 377,
CANT_BE_TARGETED_BY_BATTLECRIES = 379,
SHOWN_HERO_POWER = 380,
DEATHRATTLE_RETURN_ZONE = 382,
STEADY_SHOT_CAN_TARGET = 383,
DISPLAYED_CREATOR = 385,
POWERED_UP = 386,
SPARE_PART = 388,
FORGETFUL = 389,
CAN_SUMMON_MAXPLUSONE_MINION = 390,
OBFUSCATED = 391,
BURNING = 392,
OVERLOAD_LOCKED = 393,
NUM_TIMES_HERO_POWER_USED_THIS_GAME = 394,
CURRENT_HEROPOWER_DAMAGE_BONUS = 395,
HEROPOWER_DAMAGE = 396,
LAST_CARD_PLAYED = 397,
NUM_FRIENDLY_MINIONS_THAT_DIED_THIS_TURN = 398,
NUM_CARDS_DRAWN_THIS_TURN = 399,
AI_ONE_SHOT_KILL = 400,
EVIL_GLOW = 401,
HIDE_COST = 402,
INSPIRE = 403,
RECEIVES_DOUBLE_SPELLDAMAGE_BONUS = 404,
HEROPOWER_ADDITIONAL_ACTIVATIONS = 405,
HEROPOWER_ACTIVATIONS_THIS_TURN = 406,
REVEALED = 410,
NUM_FRIENDLY_MINIONS_THAT_DIED_THIS_GAME = 412,
CANNOT_ATTACK_HEROES = 413,
LOCK_AND_LOAD = 414,
TREASURE = 415,
SHADOWFORM = 416,
NUM_FRIENDLY_MINIONS_THAT_ATTACKED_THIS_TURN = 417,
NUM_RESOURCES_SPENT_THIS_GAME = 418,
CHOOSE_BOTH = 419,
ELECTRIC_CHARGE_LEVEL = 420,
HEAVILY_ARMORED = 421,
DONT_SHOW_IMMUNE = 422,
HISTORY_PROXY_NO_BIG_CARD = 432,
TRANSFORMED_FROM_CARD = 435,
};
#endif
+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/>.
*/
#ifndef MISC_H_
#define MISC_H_
struct gamesetup_s {
u64 board;
u64 maxsecrets;
u64 maxfriendlyminions;
u64 keepalive;
u64 stuckdisconnect;
};
struct handshake_s {
u64 gamehandle;
char *password;
int npassword;
u64 clienthandle;
u64 mission;
char *version;
int nversion;
struct platform_s *platform;
};
struct platform_s {
u64 os;
u64 screen;
int nname;
char *name;
u64 store;
};
struct chooseoption_s {
u64 id;
u64 index;
u64 target;
u64 suboption;
u64 position;
};
void gamesetup_free(struct gamesetup_s *g);
int gamesetup_serialize(void *data, char **dst, const char *maxdst);
void *gamesetup_deserialize(char **dst, const char *maxdst);
void handshake_free(struct handshake_s *h);
void *handshake_deserialize(char **dst, const char *maxdst);
int handshake_serialize(void *ao, char **dst, const char *maxdst);
void platform_free(struct platform_s *p);
struct platform_s *platform_deserialize(char **dst, const char *maxdst);
int platform_serialize(void *ao, char **dst, const char *maxdst);
int platform_size(struct platform_s *p);
int chooseoption_serialize(void *ao, char **dst, const char *maxdst);
void chooseoption_free(struct chooseoption_s *c);
void *chooseoption_deserialize(char **dst, const char *maxdst);
void chooseoption_dump(struct chooseoption_s *o, u64 local_held_card);
#endif
+34
View File
@@ -0,0 +1,34 @@
/*
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/>.
*/
#ifndef MOUSEINFO_H_
#define MOUSEINFO_H_
struct mouseinfo_s {
u64 arroworigin;
u64 heldcard;
u64 overcard;
u64 x;
u64 y;
};
void mouseinfo_free(struct mouseinfo_s *p);
void *mouseinfo_deserialize(char **dst, const char *maxdst);
int mouseinfo_serialize(void *ao, char **dst, const char *maxdst);
int mouseinfo_size(struct mouseinfo_s *p);
#endif
+60
View File
@@ -0,0 +1,60 @@
/*
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/>.
*/
#ifndef OPTIONS_H_
#define OPTIONS_H_
struct suboption_target_s {
u64 value;
struct suboption_target_s *next;
};
struct suboption_s {
u64 id;
struct suboption_target_s *target;
struct suboption_s *next;
};
struct option_s {
u64 type;
struct suboption_s *mainoption;
struct suboption_s *suboptions;
struct option_s *next;
};
struct alloptions_s {
u64 id;
struct option_s *options;
};
void alloptions_free(struct alloptions_s *a);
int alloptions_serialize(void *s, char **dst, const char *maxdst);
int alloptions_size(struct alloptions_s *p);
void option_free(struct option_s *p);
int option_serialize(struct option_s *s, char **dst, const char *maxdst);
int option_size(struct option_s *p);
void suboption_free(struct suboption_s *p);
int suboption_serialize(struct suboption_s *s, char **dst, const char *maxdst);
int suboption_size(struct suboption_s *p);
void alloptions_dump(struct alloptions_s *a);
#endif
+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/>.
*/
#ifndef PACKET_H_
#define PACKET_H_
enum packet_e {
P_GETGAMESTATE = 0x01,
P_CHOOSEOPTION = 0x02,
P_CHOOSEENTITIES = 0x03,
P_TURNTIMER = 0x09,
P_ENTITIESCHOSEN = 0x0D,
P_ALLOPTIONS = 0x0E,
P_USERUI = 0x0F,
P_GAMESETUP = 0x10,
P_ENTITYCHOICES = 0x11,
P_POWERHISTORY = 0x13,
P_SPECTATORNOTIFY = 0x18,
P_PING = 0x73,
P_PONG = 0x74,
P_HANDSHAKE = 0xA8,
};
struct packet_s {
int id;
int len;
void *data;
};
struct packet_meta_s {
int id;
void *(*deserialize)(char **dst, const char *end);
int (*serialize)(void *p, char **dst, const char *end);
int (*free)(void *p);
};
#define parse_packet(m_p, m_buf, m_nbuf)\
char *ptrd##m_buf = m_buf;\
m_p = deserialize(&ptrd##m_buf, ptrd##m_buf + m_nbuf);
#define build_packet(m_p, m_src, m_type, m_buffer)\
char m_buffer[8192];\
char *ptr##m_buffer;\
int n##m_buffer = 0;\
ptr##m_buffer = m_buffer;\
add_packet(&m_p, m_src, m_type);\
n##m_buffer = serialize(m_p, &ptr##m_buffer, ptr##m_buffer + sizeof(m_buffer));
void packet_free(struct packet_s *p);
struct packet_s *deserialize(char **dst, const char *maxdst);
int serialize(struct packet_s *p, char **dst, const char *maxdst);
struct packet_s *packet_init(enum packet_e id, void *data);
void add_packet(struct packet_s **dst, void *ph, enum packet_e n);
#endif
+174
View File
@@ -0,0 +1,174 @@
/*
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/>.
*/
#ifndef DEF_H_
#define DEF_H_
struct powerhistory_tag_s {
u64 name;
u64 value;
struct powerhistory_tag_s *next;
};
struct powerhistory_hide_s {
u64 entity;
u64 zone;
};
struct powerhistory_tagchange_s {
u64 entity;
u64 tag;
u64 value;
};
struct powerhistory_entity_s {
u64 entity;
char *name;
int nname;
struct powerhistory_tag_s *tag, *tag_tail;
};
struct powerhistory_powerstart_s {
u64 type;
u64 index;
u64 source;
u64 target;
int ncard_id;
char *card_id;
};
struct powerhistory_powerend_s {
int i;
};
struct powerhistory_game_entity_s {
u64 id;
struct powerhistory_tag_s *tag, *tag_tail;
};
struct powerhistory_s {
struct powerhistory_data_s *data, *data_tail;
};
struct powerhistory_info_s {
u64 id;
struct powerhistory_info_s *next;
};
struct powerhistory_meta_s {
u64 type;
u64 data;
struct powerhistory_info_s *info, *info_tail;
};
struct powerhistory_player_s {
u64 id;
u64 bnet_hi;
u64 bnet_lo;
u64 cardback;
struct powerhistory_game_entity_s *entity;
struct powerhistory_player_s *next;
};
struct powerhistory_creategame_s {
struct powerhistory_game_entity_s *game_entity;
struct powerhistory_player_s *player, *player_tail;
};
struct powerhistory_data_s {
struct powerhistory_entity_s *full;
struct powerhistory_entity_s *show;
struct powerhistory_hide_s *hide;
struct powerhistory_tagchange_s *tagchange;
struct powerhistory_creategame_s *creategame;
struct powerhistory_powerstart_s *powerstart;
struct powerhistory_powerend_s *powerend;
struct powerhistory_entity_s *change_entity;
struct powerhistory_meta_s *meta;
struct powerhistory_data_s *next, *tail;
};
void powerhistory_free(struct powerhistory_s *p);
void *powerhistory_deserialize(char **dst, const char *maxdst);
int powerhistory_serialize(void *data, char **dst, const char *maxdst);
int powerhistory_size(struct powerhistory_s *ph);
struct powerhistory_data_s *powerhistory_data_deserialize(char **dst, const char *maxdst);
int powerhistorydata_serialize(struct powerhistory_data_s *ph, char **dst, const char *maxdst);
int powerhistorydata_size(struct powerhistory_data_s *ph);
void powerhistory_data_free(struct powerhistory_data_s *d);
struct powerhistory_meta_s *meta_deserialize(char **dst, const char *maxdst);
int meta_serialize(struct powerhistory_meta_s *ph, char **dst, const char *maxdst);
int meta_size(struct powerhistory_meta_s *ph);
void meta_free(struct powerhistory_meta_s *t);
struct powerhistory_powerend_s *powerend_deserialize(char **dst, const char *maxdst);
int powerend_serialize(struct powerhistory_powerend_s *ph, char **dst, const char *maxdst);
int powerend_size(struct powerhistory_powerend_s *ph);
void powerend_free(struct powerhistory_powerend_s *p);
struct powerhistory_powerstart_s *powerstart_deserialize(char **dst, const char *maxdst);
int powerstart_serialize(struct powerhistory_powerstart_s *ph, char **dst, const char *maxdst);
int powerstart_size(struct powerhistory_powerstart_s *ph);
void powerstart_free(struct powerhistory_powerstart_s *p);
struct powerhistory_creategame_s *creategame_deserialize(char **dst, const char *maxdst);
int creategame_serialize(struct powerhistory_creategame_s *ph, char **dst, const char *maxdst);
int creategame_size(struct powerhistory_creategame_s *ph);
void creategame_free(struct powerhistory_creategame_s *c);
struct powerhistory_tagchange_s *tagchange_deserialize(char **dst, const char *maxdst);
int tagchange_serialize(struct powerhistory_tagchange_s *ph, char **dst, const char *maxdst);
int tagchange_size(struct powerhistory_tagchange_s *ph);
void tagchange_free(struct powerhistory_tagchange_s *t);
struct powerhistory_hide_s *hide_deserialize(char **dst, const char *maxdst);
int hide_serialize(struct powerhistory_hide_s *ph, char **dst, const char *maxdst);
int hide_size(struct powerhistory_hide_s *ph);
void hide_free(struct powerhistory_hide_s *t);
struct powerhistory_game_entity_s *game_entity_deserialize(char **dst, const char *maxdst);
int game_entity_serialize(struct powerhistory_game_entity_s *ph, char **dst, const char *maxdst);
int game_entity_size(struct powerhistory_game_entity_s *ph);
void game_entity_free(struct powerhistory_game_entity_s *g);
struct powerhistory_entity_s *entity_deserialize(char **dst, const char *maxdst);
int entity_serialize(struct powerhistory_entity_s *ph, char **dst, const char *maxdst);
int entity_size(struct powerhistory_entity_s *ph);
void entity_free(struct powerhistory_entity_s *e);
struct powerhistory_tag_s *tag_deserialize(char **dst, const char *maxdst);
int tag_serialize(struct powerhistory_tag_s *ph, char **dst, const char *maxdst);
int tag_size(struct powerhistory_tag_s *ph);
void tag_free(struct powerhistory_tag_s *t);
void player_free(struct powerhistory_player_s *p);
struct powerhistory_player_s *player_deserialize(char **dst, const char *maxdst);
int player_serialize(struct powerhistory_player_s *ph, char **dst, const char *maxdst);
int player_size(struct powerhistory_player_s *ph);
int bnet_size(struct powerhistory_player_s *ph);
void powerhistory_dump(struct powerhistory_s *p);
#endif
+68
View File
@@ -0,0 +1,68 @@
/*
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/>.
*/
#ifndef PROTO_H_
#define PROTO_H_
#define error()\
hm_log(LOG_EMERG, lg, "dst: %p end: %p n: %d", *dst, maxdst, n);\
abort();
#include <assert.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <memory.h>
#include <malloc.h>
#include <sys/time.h>
#include <time.h>
#include <ev.h>
#include <hmbase.h>
typedef unsigned long long u64;
#include <zone.h>
#include <misc.h>
#include <powerhistory.h>
#include <packet.h>
#include <gametag.h>
#include <entitychoices.h>
#include <chooseentities.h>
#include <options.h>
#include <mouseinfo.h>
#include <userui.h>
#include <turntimer.h>
int sizeofu64(u64 v);
int sizeofu32(int v);
int write_byte(char **dst, const char *end, const char src);
int write_bytes(char **dst, const char *end, const char *src, const int nsrc);
void write_uint(char **dst, const char *end, int src);
void write_uint64(char **dst, const char *end, u64 src);
int write_mem_int(char **dst, const char *end, const int src);
char read_byte(char **dst, const char *end);
int read_uint(char **dst, const char *end);
u64 read_uint64(char **dst, const char *end);
int read_mem_int(char **dst, const char *end);
char *read_bytes(char **dst, const char *end, int *ndst);
int skip(char **dst, const char *end, const int jump);
extern struct hm_log_s *lg;
#endif
+32
View File
@@ -0,0 +1,32 @@
/*
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/>.
*/
#ifndef TURNTIMER_H_
#define TURNTIMER_H_
struct turntimer_s {
u64 seconds;
u64 turn;
char show;
};
void turntimer_free(struct turntimer_s *t);
int turntimer_serialize(void *ao, char **dst, const char *maxdst);
void turntimer_dump(struct turntimer_s *t);
void *turntimer_deserialize(char **dst, const char *maxdst);
#endif
+33
View File
@@ -0,0 +1,33 @@
/*
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/>.
*/
#ifndef USERUI_H_
#define USERUI_H_
struct userui_s {
struct mouseinfo_s *mouseinfo;
u64 emote;
u64 player_id;
};
void userui_free(struct userui_s *u);
int userui_serialize(void *ao, char **dst, const char *maxdst);
void *userui_deserialize(char **dst, const char *maxdst);
int userui_size(struct userui_s *p);
void userui_dump(struct userui_s *u);
#endif
+33
View File
@@ -0,0 +1,33 @@
/*
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/>.
*/
#ifndef ZONE_H_
#define ZONE_H_
enum zone_e {
ZONE_INVALID = 0,
ZONE_PLAY = 1,
ZONE_DECK = 2,
ZONE_HAND = 3,
ZONE_GRAVEYARD = 4,
ZONE_REMOVEDFROMGAME = 5,
ZONE_SETASIDE = 6,
ZONE_SECRET = 7,
ZONE_DISCARD = -2,
};
#endif
+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;
}
+129
View File
@@ -0,0 +1,129 @@
/*
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_meta_s map_packet[MAP_PACKET_MAX] = {
{P_GETGAMESTATE, NULL, NULL, NULL},
{P_CHOOSEOPTION, chooseoption_deserialize, chooseoption_serialize, (f)chooseoption_free},
{P_TURNTIMER, turntimer_deserialize, turntimer_serialize, (f)turntimer_free},
{P_CHOOSEENTITIES, chooseentities_deserialize, chooseentities_serialize, (f)chooseentities_free},
{P_ALLOPTIONS, NULL, alloptions_serialize, (f)alloptions_free},
{P_ENTITYCHOICES, entitychoices_deserialize, entitychoices_serialize, (f)entitychoices_free},
{P_GAMESETUP, gamesetup_deserialize, 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, handshake_serialize, (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;
}
void add_packet(struct packet_s **dst, void *ph, enum packet_e n)
{
*dst = malloc(sizeof(**dst));
memset(*dst, 0, sizeof(**dst));
(*dst)->data = ph;
(*dst)->id = n;
}
+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 platform_free(struct platform_s *p)
{
free(p->name);
free(p);
}
int platform_size(struct platform_s *p)
{
int num = 0;
num += 2;
num += sizeofu64(p->os);
num += sizeofu64(p->screen);
num += 1;
num += sizeofu32(p->nname) + p->nname;
if(p->store != 0) {
num += 1;
num += sizeofu64(p->store);
}
return num;
}
int platform_serialize(void *ao, char **dst, const char *maxdst)
{
struct platform_s *s;
char *start;
start = *dst;
s = ao;
write_byte(dst, maxdst, 8);
write_uint64(dst, maxdst, s->os);
write_byte(dst, maxdst, 16);
write_uint64(dst, maxdst, s->screen);
write_byte(dst, maxdst, 26);
write_bytes(dst, maxdst, s->name, s->nname);
if(s->store != 0) {
write_byte(dst, maxdst, 32);
write_uint64(dst, maxdst, s->store);
}
return (*dst - start);
}
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;
}
+80
View File
@@ -0,0 +1,80 @@
/*
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);
}
void *turntimer_deserialize(char **dst, const char *maxdst)
{
int n;
struct turntimer_s *o;
o = malloc(sizeof(*o));
memset(o, 0, sizeof(*o));
n = read_byte(dst, maxdst);
if(n != 8) {
error();
}
o->seconds = read_uint64(dst, maxdst);
n = read_byte(dst, maxdst);
if(n != 16) {
error();
}
o->turn = read_uint64(dst, maxdst);
n = read_byte(dst, maxdst);
if(n != 24) {
error();
}
o->show = read_byte(dst, maxdst);
return o;
}
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);
}
}
}