#include <sys/stat.h>
#include <fcntl.h>
+#define DEBUG 1
+
#define DOOR_UNLOCKED_DELAY 10 // 10 seconds before it re-locks
// === IMPORTS ===
Door_CanDispense,
Door_DoDispense
};
-char *gsDoor_Password;
-char *gsDoor_Command;
+char *gsDoor_Password = "";
// int giDoor_SerialFD;
// == CODE ===
int Door_InitHandler(void)
-{
- gsDoor_Command = malloc(sizeof("llogin door -w ")+strlen(gsDoor_Password));
- sprintf(gsDoor_Command, "llogin door -w %s", gsDoor_Password);
-
+{
return 0;
}
*/
int Door_CanDispense(int User, int Item)
{
+ #if DEBUG
+ printf("Door_CanDispense: (User=%i,Item=%i)\n", User, Item);
+ #endif
// Sanity please
- if( Item == 0 ) return -1;
+ if( Item != 0 ) return -1;
if( !(Bank_GetFlags(User) & USER_FLAG_DOORGROUP) )
+ {
+ #if DEBUG
+ printf("Door_CanDispense: User %i not in door\n", User);
+ #endif
return 1;
+ }
+
+ #if DEBUG
+ printf("Door_CanDispense: User %i can open the door\n", User);
+ #endif
return 0;
}
int Door_DoDispense(int User, int Item)
{
FILE *pipe;
+ char buf[512]; // Buffer flush location - the sewer :)
+
+ #if DEBUG
+ printf("Door_DoDispense: (User=%i,Item=%i)\n", User, Item);
+ #endif
+
// Sanity please
if( Item != 0 ) return -1;
// Check if user is in door
if( !(Bank_GetFlags(User) & USER_FLAG_DOORGROUP) )
+ {
+ #if DEBUG
+ printf("Door_CanDispense: User %i not in door\n", User);
+ #endif
return 1;
+ }
// llogin or other
- //pipe = popen(gsDoor_Command, "w");
pipe = popen("llogin door -w -", "w");
- if( !pipe || pipe == (void*)-1 )
+ if( !pipe || pipe == (void*)-1 ) {
+ #if DEBUG
+ printf("Door_DoDispense: llogin failure\n");
+ #endif
return -1;
+ }
+ if( fread(buf, 512, 1, pipe) == 0 ) return -1; // Flush!
+
+ // Send password
+ fputs(gsDoor_Password, pipe);
+ fputs("\n", pipe);
+ if( fread(buf, 512, 1, pipe) == 0 ) return -1; // Flush!
- fputs(gsDoor_Password, pipe); fputs("\n", pipe);
+ // ATH1 - Unlock door
fputs("ATH1\n", pipe);
+ if( fread(buf, 512, 1, pipe) == 0 ) return -1; // Flush!
+
+ // Wait before re-locking
sleep(DOOR_UNLOCKED_DELAY);
+
+ // Re-lock the door
fputs("ATH0\n", pipe);
+ if( fread(buf, 512, 1, pipe) == 0 ) return -1; // Flush!
pclose(pipe);
+
+ #if DEBUG
+ printf("Door_DoDispense: User %i opened door\n", User);
+ #endif
return 0;
}
// TODO: User flags/type
sendf(
- Client->Socket, "202 User %s %i %s%s\n",
+ Client->Socket, "202 User %s %i %s%s%s\n",
Bank_GetAcctName(UserID), Bank_GetBalance(UserID),
- type, disabled
+ type, disabled, door
);
}
if( Server_int_ParseFlags(Client, flags, &mask, &value) )
return ;
+ if( giDebugLevel )
+ Debug(Client, "Set %i(%s) flags to %x (masked %x)\n",
+ uid, username, mask, value);
+
// Apply flags
Bank_SetFlags(uid, mask, value);