From acab1f9d02e1432d54a1cd4e0731fa104b81f48a Mon Sep 17 00:00:00 2001
From: John Hodge <tpg@ucc.gu.uwa.edu.au>
Date: Sun, 21 Nov 2010 06:02:17 +0800
Subject: [PATCH] Started on the client

- Also, fiddle, fiddle, fiddle
---
 proto.txt                 |  1 +
 src/client/Makefile       | 21 +++++++++++++++++++++
 src/client/main.c         | 38 ++++++++++++++++++++++++++++++++++++++
 src/cokebank_basic/main.c |  2 +-
 src/server/server.c       | 37 +++++++++++++++++++++++++++++++++++++
 5 files changed, 98 insertions(+), 1 deletion(-)
 create mode 100644 src/client/Makefile
 create mode 100644 src/client/main.c

diff --git a/proto.txt b/proto.txt
index 8c5e1f6..f3734aa 100644
--- a/proto.txt
+++ b/proto.txt
@@ -15,6 +15,7 @@ All server responses are on one line and are prefixed by a three digit response
 403	User not allowed to perform this action
 404	Bad other username
 406	Bad Item ID
+407	Invalid arguments
 500	Unknown Dispense Failure
 501	Action Rejected
 
diff --git a/src/client/Makefile b/src/client/Makefile
new file mode 100644
index 0000000..490e4dc
--- /dev/null
+++ b/src/client/Makefile
@@ -0,0 +1,21 @@
+
+CFLAGS := -Wall -Werror -g
+LDFLAGS := -g
+
+BIN := ../../dispense
+OBJ := main.o
+
+DEPFILES := $(OBJ:%.o=%.d)
+
+.PHONY: all clean
+
+all: $(BIN)
+
+clean:
+	$(RM) $(BIN) $(OBJ)
+
+%.o: %.c
+	$(CC) -c $< -o $@ $(CFLAGS) $(CPPFLAGS)
+	$(CC) -M -MT $@ -o $*.d $< $(CPPFLAGS)
+
+-include $(DEPFILES)
diff --git a/src/client/main.c b/src/client/main.c
new file mode 100644
index 0000000..8411181
--- /dev/null
+++ b/src/client/main.c
@@ -0,0 +1,38 @@
+/*
+ * OpenDispense 2 
+ * UCC (University [of WA] Computer Club) Electronic Accounting System
+ * - Dispense Client
+ *
+ * main.c - Core and Initialisation
+ *
+ * This file is licenced under the 3-clause BSD Licence. See the file
+ * COPYING for full details.
+ */
+#include <stdio.h>
+
+// === GLOBALS ===
+char	*gsDispenseServer = "martello";
+ int	giDispensePort = 11020;
+
+// === CODE ===
+int main(int argc, char *argv[])
+{
+	// Connect to server
+	
+
+	// Determine what to do
+	if( argc > 1 )
+	{
+		if( strcmp(argv[1], "acct") == 0 )
+		{
+			return 0;
+		}
+	}
+
+	// Ask server for stock list
+	
+	// Display the list for the user
+	// and choose what to dispense
+
+	return 0;
+}
diff --git a/src/cokebank_basic/main.c b/src/cokebank_basic/main.c
index fbc8f6e..96888c0 100644
--- a/src/cokebank_basic/main.c
+++ b/src/cokebank_basic/main.c
@@ -79,7 +79,7 @@ int Transfer(int SourceUser, int DestUser, int Ammount, const char *Reason)
  */
 int GetBalance(int User)
 {
-	return 0;
+	return Bank_GetUserBalance(User);;
 }
 
 /**
diff --git a/src/server/server.c b/src/server/server.c
index 9f59489..7866274 100644
--- a/src/server/server.c
+++ b/src/server/server.c
@@ -465,6 +465,43 @@ char *Server_Cmd_DISPENSE(tClient *Client, char *Args)
 	}
 }
 
+char *Server_Cmd_GIVE(tClient *Client, char *Args)
+{
+	char	*recipient, *ammount, *reason;
+	 int	uid, iAmmount;
+	
+	if( !Client->bIsAuthed )	return strdup("401 Not Authenticated\n");
+
+	recipient = Args;
+
+	ammount = strchr(Args, ' ');
+	if( !ammount )	return strdup("407 Invalid Argument, expected 3 parameters, 1 encountered\n");
+	*ammount = '\0';
+	ammount ++;
+
+	reason = strchr(ammount, ' ');
+	if( !reason )	return strdup("407 Invalid Argument, expected 3 parameters, 2 encountered\n");
+	*reason = '\0';
+	reason ++;
+
+	// Get recipient
+	uid = GetUserID(recipient);
+	if( uid == -1 )	return strdup("404 Invalid target user");
+
+	// Parse ammount
+	iAmmount = atoi(ammount);
+	if( iAmmount <= 0 )	return strdup("407 Invalid Argument, ammount must be > zero\n");
+
+	// Do give
+	switch( Transfer(Client->UID, uid, iAmmount, reason) )
+	{
+	case 0:
+		return strdup("200 Give OK\n");
+	default:
+		return strdup("402 Poor You\n");
+	}
+}
+
 // --- INTERNAL HELPERS ---
 // TODO: Move to another file
 void HexBin(uint8_t *Dest, char *Src, int BufSize)
-- 
GitLab