Commit 8657c2f2 authored by salix5's avatar salix5

add LEN_FAIL, LEN_HEADER

LEN_FAIL: wrong player id or wrong location
parent 04aa9301
...@@ -177,26 +177,28 @@ extern "C" DECL_DLLEXPORT void new_tag_card(intptr_t pduel, uint32 code, uint8 o ...@@ -177,26 +177,28 @@ extern "C" DECL_DLLEXPORT void new_tag_card(intptr_t pduel, uint32 code, uint8 o
} }
extern "C" DECL_DLLEXPORT int32 query_card(intptr_t pduel, uint8 playerid, uint8 location, uint8 sequence, int32 query_flag, byte* buf, int32 use_cache) { extern "C" DECL_DLLEXPORT int32 query_card(intptr_t pduel, uint8 playerid, uint8 location, uint8 sequence, int32 query_flag, byte* buf, int32 use_cache) {
if(playerid != 0 && playerid != 1) if(playerid != 0 && playerid != 1)
return 0; return LEN_FAIL;
duel* ptduel = (duel*)pduel; duel* ptduel = (duel*)pduel;
card* pcard = 0; card* pcard = nullptr;
location &= 0x7f; location &= 0x7f;
if(location & LOCATION_ONFIELD) if(location & LOCATION_ONFIELD)
pcard = ptduel->game_field->get_field_card(playerid, location, sequence); pcard = ptduel->game_field->get_field_card(playerid, location, sequence);
else { else {
field::card_vector* lst = 0; field::card_vector* lst = nullptr;
if(location == LOCATION_HAND) if (location == LOCATION_HAND)
lst = &ptduel->game_field->player[playerid].list_hand; lst = &ptduel->game_field->player[playerid].list_hand;
else if(location == LOCATION_GRAVE) else if (location == LOCATION_GRAVE)
lst = &ptduel->game_field->player[playerid].list_grave; lst = &ptduel->game_field->player[playerid].list_grave;
else if(location == LOCATION_REMOVED) else if (location == LOCATION_REMOVED)
lst = &ptduel->game_field->player[playerid].list_remove; lst = &ptduel->game_field->player[playerid].list_remove;
else if(location == LOCATION_EXTRA) else if (location == LOCATION_EXTRA)
lst = &ptduel->game_field->player[playerid].list_extra; lst = &ptduel->game_field->player[playerid].list_extra;
else if(location == LOCATION_DECK) else if (location == LOCATION_DECK)
lst = &ptduel->game_field->player[playerid].list_main; lst = &ptduel->game_field->player[playerid].list_main;
if(!lst || sequence >= lst->size()) else
pcard = 0; return LEN_FAIL;
if(sequence >= (int32)lst->size())
pcard = nullptr;
else else
pcard = (*lst)[sequence]; pcard = (*lst)[sequence];
} }
...@@ -241,7 +243,7 @@ extern "C" DECL_DLLEXPORT int32 query_field_count(intptr_t pduel, uint8 playerid ...@@ -241,7 +243,7 @@ extern "C" DECL_DLLEXPORT int32 query_field_count(intptr_t pduel, uint8 playerid
} }
extern "C" DECL_DLLEXPORT int32 query_field_card(intptr_t pduel, uint8 playerid, uint8 location, uint32 query_flag, byte* buf, int32 use_cache) { extern "C" DECL_DLLEXPORT int32 query_field_card(intptr_t pduel, uint8 playerid, uint8 location, uint32 query_flag, byte* buf, int32 use_cache) {
if(playerid != 0 && playerid != 1) if(playerid != 0 && playerid != 1)
return 0; return LEN_FAIL;
duel* ptduel = (duel*)pduel; duel* ptduel = (duel*)pduel;
auto& player = ptduel->game_field->player[playerid]; auto& player = ptduel->game_field->player[playerid];
byte* p = buf; byte* p = buf;
...@@ -280,7 +282,7 @@ extern "C" DECL_DLLEXPORT int32 query_field_card(intptr_t pduel, uint8 playerid, ...@@ -280,7 +282,7 @@ extern "C" DECL_DLLEXPORT int32 query_field_card(intptr_t pduel, uint8 playerid,
else if(location == LOCATION_DECK) else if(location == LOCATION_DECK)
lst = &player.list_main; lst = &player.list_main;
else else
return 0; return LEN_FAIL;
for(auto& pcard : *lst) { for(auto& pcard : *lst) {
int32 clen = pcard->get_infos(p, query_flag, use_cache); int32 clen = pcard->get_infos(p, query_flag, use_cache);
p += clen; p += clen;
......
...@@ -16,7 +16,9 @@ ...@@ -16,7 +16,9 @@
#define DECL_DLLEXPORT #define DECL_DLLEXPORT
#endif #endif
#define LEN_FAIL 0
#define LEN_EMPTY 4 #define LEN_EMPTY 4
#define LEN_HEADER 8
class card; class card;
struct card_data; struct card_data;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment