X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=src%2Fserver%2Fserver.c;h=01e2d841956d8c8794fe8106dedebfcb60b43fa2;hb=b8913d7420311a9eb7da923a8fc645ac4ca25a45;hp=4c686d94bc2e4c4c277962ff29cc97eb2d3bf555;hpb=9ee11856849fa782af3b477d0d9172a7211d7f2e;p=tpg%2Fopendispense2.git diff --git a/src/server/server.c b/src/server/server.c index 4c686d9..01e2d84 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -303,7 +303,7 @@ void Server_ParseClientCommand(tClient *Client, char *CommandString) if( Server_int_ParseArgs(1, CommandString, &command, &args, NULL) ) { - printf("command=%s, args=%s\n", command, args); +// printf("command=%s, args=%s\n", command, args); // Is this an error? (just ignore for now) //args = ""; } @@ -486,6 +486,32 @@ void Server_Cmd_SETEUSER(tClient *Client, char *Args) sendf(Client->Socket, "200 User set\n"); } +/** + * \brief Send an item status to the client + * \param Client Who to? + * \param Item Item to send + */ +void Server_int_SendItem(tClient *Client, tItem *Item) +{ + char *status = "avail"; + + if( Item->Handler->CanDispense ) + { + switch(Item->Handler->CanDispense(Client->UID, Item->ID)) + { + case 0: status = "avail"; break; + case 1: status = "sold"; break; + default: + case -1: status = "error"; break; + } + } + + sendf(Client->Socket, + "202 Item %s:%i %s %i %s\n", + Item->Handler->Name, Item->ID, status, Item->Price, Item->Name + ); +} + /** * \brief Enumerate the items that the server knows about */ @@ -509,10 +535,7 @@ void Server_Cmd_ENUMITEMS(tClient *Client, char *Args) for( i = 0; i < giNumItems; i ++ ) { if( gaItems[i].bHidden ) continue; - sendf(Client->Socket, - "202 Item %s:%i %i %s\n", - gaItems[i].Handler->Name, gaItems[i].ID, gaItems[i].Price, gaItems[i].Name - ); + Server_int_SendItem( Client, &gaItems[i] ); } sendf(Client->Socket, "200 List end\n"); @@ -574,10 +597,7 @@ void Server_Cmd_ITEMINFO(tClient *Client, char *Args) return ; } - sendf(Client->Socket, - "202 Item %s:%i %i %s\n", - item->Handler->Name, item->ID, item->Price, item->Name - ); + Server_int_SendItem( Client, item ); } void Server_Cmd_DISPENSE(tClient *Client, char *Args) @@ -1201,7 +1221,6 @@ int Server_int_ParseArgs(int bUseLongLast, char *ArgStr, ...) while( (dest = va_arg(args, char **)) ) { - printf(" dest = %p\n", dest); // Trim leading spaces while( *ArgStr == ' ' || *ArgStr == '\t' ) ArgStr ++;