pseudo 4 2500 membership # here comes the money!
# Snack machine
-#snack 13 128 Smiths Salt & Vinegar
-#snack 33 128 Smiths Original
+-snack 13 128 Smiths Salt & Vinegar
+-snack 33 128 Smiths Original
+-snack 53 128 Smiths Barbeque
}
- // Connect to server again
- sock = OpenConnection(gsDispenseServer, giDispensePort);
- if( sock < 0 ) return -1;
-
- // Authenticate
- Authenticate(sock);
-
// Check for a valid item ID
if( i >= 0 )
+ {
+ // Connect, Authenticate, dispense and close
+ sock = OpenConnection(gsDispenseServer, giDispensePort);
+ if( sock < 0 ) return -1;
+ Authenticate(sock);
DispenseItem(sock, i);
-
- close(sock);
+ close(sock);
+ }
return 0;
}
{
char *Name; //!< Display Name
int Price; //!< Price
+ int bHidden; //!< Hidden item?
tHandler *Handler; //!< Handler for the item
short ID; //!< Item ID
#include "common.h"
#include <stdlib.h>
#include <limits.h>
+#include <string.h>
int _GetMinBalance(int Account);
int _CanTransfer(int Source, int Destination, int Ammount);
#include <ctype.h>
#include "common.h"
#include <regex.h>
+#include <sys/inotify.h>
+#include <signal.h>
+#include <sys/fcntl.h>
+#include <unistd.h>
// === IMPORTS ===
extern tHandler gCoke_Handler;
extern tHandler gDoor_Handler;
// === PROTOTYPES ===
+void Init_Handlers(void);
+void ItemList_Changed(int signum);
void Load_Itemlist(void);
char *trim(char *__str);
tHandler *gaHandlers[] = {&gPseudo_Handler, &gCoke_Handler, &gSnack_Handler, &gDoor_Handler};
int giNumHandlers = sizeof(gaHandlers)/sizeof(gaHandlers[0]);
char *gsItemListFile = DEFAULT_ITEM_FILE;
+#if USE_INOTIFY
+ int giItem_INotifyFD;
+#endif
// === CODE ===
void Init_Handlers()
if( gaHandlers[i]->Init )
gaHandlers[i]->Init(0, NULL); // TODO: Arguments
}
+
+ // Use inotify to watch the snack config file
+ #if USE_INOTIFY
+ {
+ int oflags;
+
+ giItem_INotifyFD = inotify_init();
+ inotify_add_watch(giItem_INotifyFD, gsItemListFile, IN_MODIFY);
+
+ // Handle SIGIO
+ signal(SIGIO, &ItemList_Changed);
+
+ // Fire SIGIO when data is ready on the FD
+ fcntl(giItem_INotifyFD, F_SETOWN, getpid());
+ oflags = fcntl(giItem_INotifyFD, F_GETFL);
+ fcntl(giItem_INotifyFD, F_SETFL, oflags | FASYNC);
+ }
+ #endif
+}
+
+#if USE_INOTIFY
+void ItemList_Changed(int signum)
+{
+ char buf[512];
+ read(giItem_INotifyFD, buf, 512);
+ Load_Itemlist();
+
+ signum = 0; // Shut up GCC
}
+#endif
/**
* \brief Read the item list from disk
regex_t regex;
regmatch_t matches[5];
- i = regcomp(®ex, "^([a-zA-Z][a-zA-Z0-9]*)\\s+([0-9]+)\\s+([0-9]+)\\s+(.*)", REG_EXTENDED);
+ i = regcomp(®ex, "^-?([a-zA-Z][a-zA-Z0-9]*)\\s+([0-9]+)\\s+([0-9]+)\\s+(.*)", REG_EXTENDED);
if( i )
{
size_t len = regerror(i, ®ex, NULL, 0);
gaItems[giNumItems].ID = num;
gaItems[giNumItems].Price = price;
gaItems[giNumItems].Name = strdup(desc);
+ gaItems[giNumItems].bHidden = (line[0] == '-');
giNumItems ++;
}
}
extern char *gsItemListFile;
extern char *gsCoke_SerialPort;
extern char *gsSnack_SerialPort;
+extern char *gsDoor_Password;
// === GLOBALS ===
int giDebugLevel = 0;
switch(arg[1])
{
case 'p':
+ if( i + 1 >= argc ) return -1;
giServer_Port = atoi(argv[++i]);
break;
case 'd':
+ if( i + 1 >= argc ) return -1;
giDebugLevel = atoi(argv[++i]);
break;
default:
}
else if( arg[0] == '-' && arg[1] == '-' ) {
if( strcmp(arg, "--itemsfile") == 0 ) {
+ if( i + 1 >= argc ) return -1;
gsItemListFile = argv[++i];
}
else if( strcmp(arg, "--cokeport") == 0 ) {
+ if( i + 1 >= argc ) return -1;
gsCoke_SerialPort = argv[++i];
}
else if( strcmp(arg, "--snackport") == 0 ) {
+ if( i + 1 >= argc ) return -1;
gsSnack_SerialPort = argv[++i];
}
+ else if( strcmp(arg, "--doorpass") == 0 ) {
+ if( i + 1 >= argc ) return -1;
+ gsDoor_Password = argv[++i];
+ }
else {
// Usage error?
}
*/
void Server_Cmd_ENUMITEMS(tClient *Client, char *Args)
{
- int i;
+ int i, count;
if( Args != NULL && strlen(Args) ) {
sendf(Client->Socket, "407 ENUM_ITEMS takes no arguments\n");
return ;
}
+
+ // Count shown items
+ count = 0;
+ for( i = 0; i < giNumItems; i ++ ) {
+ if( gaItems[i].bHidden ) continue;
+ count ++;
+ }
- sendf(Client->Socket, "201 Items %i\n", giNumItems);
+ sendf(Client->Socket, "201 Items %i\n", count);
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