$(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)
int Dispense_AlterBalance(int Socket, const char *Username, int Ammount, const char *Reason)
{
char *buf;
- int responseCode;
+ int responseCode, rv = -1;
// Check for a dry run
if( gbDryRun ) {
buf = ReadLine(Socket);
responseCode = atoi(buf);
- free(buf);
switch(responseCode)
{
- case 200: return 0; // OK
+ case 200:
+ rv = 0; // OK
+ break;
case 402:
fprintf(stderr, "Insufficient balance\n");
- return RV_BAD_ITEM;
+ rv = RV_BAD_ITEM;
+ break;
case 403: // Not in coke
fprintf(stderr, "You are not in coke (sucker)\n");
- return RV_PERMISSIONS;
+ rv = RV_PERMISSIONS;
+ break;
case 404: // Unknown user
fprintf(stderr, "Unknown user '%s'\n", Username);
- return RV_INVALID_USER;
+ rv = RV_INVALID_USER;
+ break;
default:
- 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(buf);
- return -1;
+ return rv;
}
/**
free(ret);
return strdup("499 Client Connection Error\n");
}
- buf[bufPos+len] = '\0';
}
+ buf[bufPos+len] = '\0';
newline = strchr( buf+bufPos, '\n' );
if( newline ) {
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
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);
#endif
/**
- * \brief Read the initiali item list
+ * \brief Read the initial item list
*/
void Load_Itemlist(void)
{
struct sPeriodicCall {
void (*Function)(void);
} gaPeriodicCalls[ciMaxPeriodics];
+pthread_t gTimerThread;
// === CODE ===
void sigint_handler()
int main(int argc, char *argv[])
{
int i;
- pthread_t timer_thread;
// Parse Arguments
for( i = 1; i < argc; i++ )
gbServer_RunInBackground = 1;
}
else if( strcmp(arg, "--dont-daemonise") == 0 ) {
- gbServer_RunInBackground = 1;
+ gbServer_RunInBackground = 0;
}
else {
// Usage error?
Load_Itemlist();
- pthread_create( &timer_thread, NULL, Periodic_Thread, NULL );
-
Server_Start();
- pthread_kill(timer_thread, SIGKILL);
+ pthread_kill(gTimerThread, SIGKILL);
return 0;
}
return NULL;
}
+void StartPeriodicThread(void)
+{
+ pthread_create( &gTimerThread, NULL, Periodic_Thread, NULL );
+}
+
void AddPeriodicFunction(void (*Fcn)(void))
{
int i;
#include <signal.h>
#define DEBUG_TRACE_CLIENT 0
+#define HACK_NO_REFUNDS 1
// Statistics
#define MAX_CONNECTION_QUEUE 5
dup2(newout, 1);
dup2(newerr, 2);
}
+
+ // Start the helper thread
+ StartPeriodicThread();
// Listen
if( listen(giServer_Socket, MAX_CONNECTION_QUEUE) < 0 ) {
return ;
}
+ #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 ) {