Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: KillingNoisesWorkgroup/ChessGame
base: 4603dd6951
...
head fork: KillingNoisesWorkgroup/ChessGame
compare: 6317398779
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
53 src/client/callbacks.c
View
@@ -18,10 +18,28 @@
// Variable names must be all the same as in the prototype for
// fancy helpers to work properly
-// Callbacks
+// Callbacks definitions
+
+void cb_remote_ingame(int ptype, int plen, void *payload);
+void cb_remote_default(int ptype, int plen, void *payload);
+void cb_remote_new_game_autoconnect(int ptype, int plen, void *payload);
+
+void cb_local_ingame(char *buff, int len);
+void cb_local_default(char *buff, int len);
+
+// Implementation
void cb_remote_ingame(int ptype, int plen, void *payload) {
- on packet(PACKET_GENERAL_STRING) {
+ on packet(PACKET_GAME_DETACH) {
+
+ reactor.callback_remote = NULL;
+ reactor.callback_local = NULL;
+ session.state.current = GAMESTATE_LOBBY;
+
+ output("You are now in lobby!\n");
+ print_prompt();
+
+ } packet(PACKET_GENERAL_STRING) {
// Force string end
((char *)payload)[plen - 1] = '\0';
@@ -42,6 +60,7 @@ void cb_remote_default(int ptype, int plen, void *payload) {
int gameid = ntohl(p->gameid);
reactor.callback_remote = &cb_remote_ingame;
+ reactor.callback_local = &cb_local_ingame;
session.state.current = GAMESTATE_INGAME;
snprintf(session.state.game_name, sizeof session.state.game_name, "%s", p->game_name);
session.state.team = p->attached_as_team;
@@ -86,6 +105,36 @@ void cb_remote_new_game_autoconnect(int ptype, int plen, void *payload) {
send_game_attach_request(session.socket, gameid, TEAM_AUTO);
}
+void cb_local_ingame(char *buff, int len) {
+ tokenizer_init;
+
+ on command("help") {
+
+ output("Commands list:\n");
+ output(" I from to - move figure from <from> position to <to>\n");
+ output(" detach - quit current game session\n");
+ output(" help - this message\n");
+ output(" exit - exit the app\n");
+
+ } command("detach") {
+
+ output("Detaching a game...\n");
+ send_game_detach_request(session.socket);
+ ommit_next_autoprompt++;
+
+ } command("exit") {
+
+ output("Bye!\n");
+ exit(EXIT_SUCCESS);
+
+ } else {
+ if(tokget(cmd, 0))
+ output("Unknown command \"%s\"! Try using \"help\".\n", tokget(cmd, 0));
+ }
+
+ tokenizer_free;
+}
+
void cb_local_default(char *buff, int len) {
tokenizer_init;
4 src/client/packet_helpers.c
View
@@ -27,3 +27,7 @@ int send_game_attach_request(int dst, uint32_t gameid, uint8_t team) {
int send_games_list_request(int dst) {
return packet_send(dst, PACKET_GAMES_LIST_REQUEST, 0, NULL);
}
+
+int send_game_detach_request(int dst) {
+ return packet_send(dst, PACKET_GAME_DETACH_REQUEST, 0, NULL);
+}
1  src/client/packet_helpers.h
View
@@ -5,5 +5,6 @@ int send_shutdown(int dst);
int send_game_creation_request(int dst, char *name);
int send_game_attach_request(int dst, uint32_t gameid, uint8_t team);
int send_games_list_request(int dst);
+int send_game_detach_request(int dst);
#endif
16 src/shared/packets.h
View
@@ -82,3 +82,19 @@ typedef struct packet_game_attach{
typedef struct packet_games_list_request{
// empty
} packet_games_list_request;
+
+
+/* PACKET C2S - Game detach request */
+
+#define PACKET_GAME_DETACH_REQUEST 9
+typedef struct packet_game_detach_request{
+ // empty
+} packet_game_detach_request;
+
+
+/* PACKET S2C - Game detach response */
+
+#define PACKET_GAME_DETACH 10
+typedef struct packet_game_detach{
+ // empty
+} packet_game_detach;

No commit comments for this range

Something went wrong with that request. Please try again.