git.ucc.asn.au
/
tpg
/
opendispense2.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
45a676d
)
Door config settings (and some fixes to doorgroup reporting)
author
John Hodge
<
[email protected]
>
Sat, 19 Feb 2011 08:07:50 +0000
(16:07 +0800)
committer
John Hodge
<
[email protected]
>
Sat, 19 Feb 2011 08:07:50 +0000
(16:07 +0800)
RunServerTest
patch
|
blob
|
history
items.cfg
patch
|
blob
|
history
src/cokebank_sqlite/main.c
patch
|
blob
|
history
src/server/handler_door.c
patch
|
blob
|
history
src/server/server.c
patch
|
blob
|
history
diff --git
a/RunServerTest
b/RunServerTest
index
b117c70
..
a72a3fa
100755
(executable)
--- a/
RunServerTest
+++ b/
RunServerTest
@@
-2,6
+2,7
@@
ARGS="--itemsfile items.cfg -p 11020"
ARGS=$ARGS" --cokeport /dev/ttyUSB0"
ARGS="--itemsfile items.cfg -p 11020"
ARGS=$ARGS" --cokeport /dev/ttyUSB0"
+ARGS=$ARGS" -d 2"
if [ "x$2" != "x" ]; then
_cokebank=$1
if [ "x$2" != "x" ]; then
_cokebank=$1
diff --git
a/items.cfg
b/items.cfg
index
ef85035
..
f8e7106
100644
(file)
--- a/
items.cfg
+++ b/
items.cfg
@@
-17,6
+17,8
@@
pseudo 2 128 clue # clue.flac - Dont' Ask
pseudo 3 3500 polo postorder # Polo Shirt! (With UCC Sun Logo)
pseudo 4 2500 membership # here comes the money!
pseudo 3 3500 polo postorder # Polo Shirt! (With UCC Sun Logo)
pseudo 4 2500 membership # here comes the money!
+door 0 0 Open Door # Open Sesame
+
# Snack machine
-snack 13 128 Smiths Salt & Vinegar
-snack 33 128 Smiths Original
# Snack machine
-snack 13 128 Smiths Salt & Vinegar
-snack 33 128 Smiths Original
diff --git
a/src/cokebank_sqlite/main.c
b/src/cokebank_sqlite/main.c
index
e539105
..
23776b3
100644
(file)
--- a/
src/cokebank_sqlite/main.c
+++ b/
src/cokebank_sqlite/main.c
@@
-220,6
+220,10
@@
int Bank_SetFlags(int UserID, int Mask, int Value)
);
#undef MAP_FLAG
);
#undef MAP_FLAG
+ #if DEBUG
+ printf("Bank_SetFlags: query=\"%s\"\n", query);
+ #endif
+
// Execute Query
rv = sqlite3_exec(gBank_Database, query, NULL, NULL, &errmsg);
if( rv != SQLITE_OK )
// Execute Query
rv = sqlite3_exec(gBank_Database, query, NULL, NULL, &errmsg);
if( rv != SQLITE_OK )
diff --git
a/src/server/handler_door.c
b/src/server/handler_door.c
index
978c184
..
9942526
100644
(file)
--- a/
src/server/handler_door.c
+++ b/
src/server/handler_door.c
@@
-14,6
+14,8
@@
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <fcntl.h>
+#define DEBUG 1
+
#define DOOR_UNLOCKED_DELAY 10 // 10 seconds before it re-locks
// === IMPORTS ===
#define DOOR_UNLOCKED_DELAY 10 // 10 seconds before it re-locks
// === IMPORTS ===
@@
-30,16
+32,12
@@
tHandler gDoor_Handler = {
Door_CanDispense,
Door_DoDispense
};
Door_CanDispense,
Door_DoDispense
};
-char *gsDoor_Password;
-char *gsDoor_Command;
+char *gsDoor_Password = "";
// int giDoor_SerialFD;
// == CODE ===
int Door_InitHandler(void)
// 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;
}
return 0;
}
@@
-47,11
+45,23
@@
int Door_InitHandler(void)
*/
int Door_CanDispense(int User, int Item)
{
*/
int Door_CanDispense(int User, int Item)
{
+ #if DEBUG
+ printf("Door_CanDispense: (User=%i,Item=%i)\n", User, Item);
+ #endif
// Sanity please
// Sanity please
- if( Item
=
= 0 ) return -1;
+ if( Item
!
= 0 ) return -1;
if( !(Bank_GetFlags(User) & USER_FLAG_DOORGROUP) )
if( !(Bank_GetFlags(User) & USER_FLAG_DOORGROUP) )
+ {
+ #if DEBUG
+ printf("Door_CanDispense: User %i not in door\n", User);
+ #endif
return 1;
return 1;
+ }
+
+ #if DEBUG
+ printf("Door_CanDispense: User %i can open the door\n", User);
+ #endif
return 0;
}
return 0;
}
@@
-62,25
+72,55
@@
int Door_CanDispense(int User, int Item)
int Door_DoDispense(int User, int Item)
{
FILE *pipe;
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) )
// 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;
return 1;
+ }
// llogin or other
// llogin or other
- //pipe = popen(gsDoor_Command, "w");
pipe = popen("llogin door -w -", "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;
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);
fputs("ATH1\n", pipe);
+ if( fread(buf, 512, 1, pipe) == 0 ) return -1; // Flush!
+
+ // Wait before re-locking
sleep(DOOR_UNLOCKED_DELAY);
sleep(DOOR_UNLOCKED_DELAY);
+
+ // Re-lock the door
fputs("ATH0\n", pipe);
fputs("ATH0\n", pipe);
+ if( fread(buf, 512, 1, pipe) == 0 ) return -1; // Flush!
pclose(pipe);
pclose(pipe);
+
+ #if DEBUG
+ printf("Door_DoDispense: User %i opened door\n", User);
+ #endif
return 0;
}
return 0;
}
diff --git
a/src/server/server.c
b/src/server/server.c
index
4379317
..
cd69224
100644
(file)
--- a/
src/server/server.c
+++ b/
src/server/server.c
@@
-1095,9
+1095,9
@@
void _SendUserInfo(tClient *Client, int UserID)
// TODO: User flags/type
sendf(
// 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),
Bank_GetAcctName(UserID), Bank_GetBalance(UserID),
- type, disabled
+ type, disabled
, door
);
}
);
}
@@
-1172,6
+1172,10
@@
void Server_Cmd_USERFLAGS(tClient *Client, char *Args)
if( Server_int_ParseFlags(Client, flags, &mask, &value) )
return ;
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);
// Apply flags
Bank_SetFlags(uid, mask, value);
UCC
git Repository :: git.ucc.asn.au