- Client fixed to pass error messages correctly
- Fiddling with client ReadLine (was infinite looping, should be fixed now)
- Fixed server to start the timer thread in the main process (not the parent)
- Added a hack to detect refund `dispense acct` messages and reject them
$(BIN): $(OBJ)
$(CC) -o $(BIN) $(OBJ) $(LDFLAGS)
$(BIN): $(OBJ)
$(CC) -o $(BIN) $(OBJ) $(LDFLAGS)
- chown root $(BIN)
- chmod u+s $(BIN)
+# chown root $(BIN)
+# chmod u+s $(BIN)
%.o: %.c
$(CC) -c $< -o $@ $(CFLAGS) $(CPPFLAGS)
%.o: %.c
$(CC) -c $< -o $@ $(CFLAGS) $(CPPFLAGS)
int Dispense_AlterBalance(int Socket, const char *Username, int Ammount, const char *Reason)
{
char *buf;
int Dispense_AlterBalance(int Socket, const char *Username, int Ammount, const char *Reason)
{
char *buf;
+ int responseCode, rv = -1;
// Check for a dry run
if( gbDryRun ) {
// Check for a dry run
if( gbDryRun ) {
buf = ReadLine(Socket);
responseCode = atoi(buf);
buf = ReadLine(Socket);
responseCode = atoi(buf);
- case 200: return 0; // OK
+ case 200:
+ rv = 0; // OK
+ break;
case 402:
fprintf(stderr, "Insufficient balance\n");
case 402:
fprintf(stderr, "Insufficient balance\n");
+ rv = RV_BAD_ITEM;
+ break;
case 403: // Not in coke
fprintf(stderr, "You are not in coke (sucker)\n");
case 403: // Not in coke
fprintf(stderr, "You are not in coke (sucker)\n");
+ rv = RV_PERMISSIONS;
+ break;
case 404: // Unknown user
fprintf(stderr, "Unknown user '%s'\n", Username);
case 404: // Unknown user
fprintf(stderr, "Unknown user '%s'\n", Username);
- return RV_INVALID_USER;
+ rv = RV_INVALID_USER;
+ break;
- fprintf(stderr, "Unknown response code %i\n", responseCode);
- return RV_UNKNOWN_RESPONSE;
+ fprintf(stderr, "Unknown response code %i\n'%s'\n", responseCode, buf);
+ rv = RV_UNKNOWN_RESPONSE;
+ break;
free(ret);
return strdup("499 Client Connection Error\n");
}
free(ret);
return strdup("499 Client Connection Error\n");
}
- buf[bufPos+len] = '\0';
+ buf[bufPos+len] = '\0';
newline = strchr( buf+bufPos, '\n' );
if( newline ) {
newline = strchr( buf+bufPos, '\n' );
if( newline ) {
char *Name; //!< Display Name
int Price; //!< Price
int bHidden; //!< Hidden item?
char *Name; //!< Display Name
int Price; //!< Price
int bHidden; //!< Hidden item?
+ int bDisabledi; //!< Disabled Item
tHandler *Handler; //!< Handler for the item
short ID; //!< Item ID
tHandler *Handler; //!< Handler for the item
short ID; //!< Item ID
extern void Items_UpdateFile(void);
// --- Helpers --
extern void Items_UpdateFile(void);
// --- Helpers --
+extern void StartPeriodicThread(void);
extern void AddPeriodicFunction(void (*Fcn)(void));
extern void CompileRegex(regex_t *Regex, const char *Pattern, int Flags);
extern int RunRegex(regex_t *regex, const char *string, int nMatches, regmatch_t *matches, const char *errorMessage);
extern void AddPeriodicFunction(void (*Fcn)(void));
extern void CompileRegex(regex_t *Regex, const char *Pattern, int Flags);
extern int RunRegex(regex_t *regex, const char *string, int nMatches, regmatch_t *matches, const char *errorMessage);
- * \brief Read the initiali item list
+ * \brief Read the initial item list
*/
void Load_Itemlist(void)
{
*/
void Load_Itemlist(void)
{
struct sPeriodicCall {
void (*Function)(void);
} gaPeriodicCalls[ciMaxPeriodics];
struct sPeriodicCall {
void (*Function)(void);
} gaPeriodicCalls[ciMaxPeriodics];
// === CODE ===
void sigint_handler()
// === CODE ===
void sigint_handler()
int main(int argc, char *argv[])
{
int i;
int main(int argc, char *argv[])
{
int i;
- pthread_t timer_thread;
// Parse Arguments
for( i = 1; i < argc; i++ )
// Parse Arguments
for( i = 1; i < argc; i++ )
gbServer_RunInBackground = 1;
}
else if( strcmp(arg, "--dont-daemonise") == 0 ) {
gbServer_RunInBackground = 1;
}
else if( strcmp(arg, "--dont-daemonise") == 0 ) {
- gbServer_RunInBackground = 1;
+ gbServer_RunInBackground = 0;
- pthread_create( &timer_thread, NULL, Periodic_Thread, NULL );
-
- pthread_kill(timer_thread, SIGKILL);
+ pthread_kill(gTimerThread, SIGKILL);
+void StartPeriodicThread(void)
+{
+ pthread_create( &gTimerThread, NULL, Periodic_Thread, NULL );
+}
+
void AddPeriodicFunction(void (*Fcn)(void))
{
int i;
void AddPeriodicFunction(void (*Fcn)(void))
{
int i;
#include <signal.h>
#define DEBUG_TRACE_CLIENT 0
#include <signal.h>
#define DEBUG_TRACE_CLIENT 0
+#define HACK_NO_REFUNDS 1
// Statistics
#define MAX_CONNECTION_QUEUE 5
// Statistics
#define MAX_CONNECTION_QUEUE 5
dup2(newout, 1);
dup2(newerr, 2);
}
dup2(newout, 1);
dup2(newerr, 2);
}
+
+ // Start the helper thread
+ StartPeriodicThread();
// Listen
if( listen(giServer_Socket, MAX_CONNECTION_QUEUE) < 0 ) {
// Listen
if( listen(giServer_Socket, MAX_CONNECTION_QUEUE) < 0 ) {
+ #if HACK_NO_REFUNDS
+ if( strstr(reason, "refund") != NULL || strstr(reason, "misdispense") != NULL )
+ {
+ sendf(Client->Socket, "499 Don't use `dispense acct` for refunds, use `dispense refund` (and `dispense -G` to get item IDs)\n");
+ return ;
+ }
+ #endif
+
// Get recipient
uid = Bank_GetAcctByName(user, 0);
if( uid == -1 ) {
// Get recipient
uid = Bank_GetAcctByName(user, 0);
if( uid == -1 ) {