about summary refs log tree commit diff
path: root/src/game
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2008-08-27 19:41:02 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2008-08-27 19:41:02 +0000
commit8f23204eef956177855ee8fb9c1cc21cd08560f4 (patch)
treed44020f0a15f1b676f7cd221cbb17ea40fab54c1 /src/game
parent68c52dd5efca7ed66b083b70439337b8f1205c15 (diff)
downloadzcatch-8f23204eef956177855ee8fb9c1cc21cd08560f4.tar.gz
zcatch-8f23204eef956177855ee8fb9c1cc21cd08560f4.zip
fixed the chat
Diffstat (limited to 'src/game')
-rw-r--r--src/game/client/components/chat.cpp51
-rw-r--r--src/game/client/components/chat.hpp8
2 files changed, 42 insertions, 17 deletions
diff --git a/src/game/client/components/chat.cpp b/src/game/client/components/chat.cpp
index ecd29ab8..2e481215 100644
--- a/src/game/client/components/chat.cpp
+++ b/src/game/client/components/chat.cpp
@@ -1,3 +1,9 @@
+#include <string.h> // strcmp
+
+extern "C" {
+	#include <engine/e_console.h>
+}
+
 #include <engine/e_client_interface.h>
 #include <game/generated/g_protocol.hpp>
 #include <game/generated/gc_data.hpp>
@@ -17,6 +23,35 @@ void CHAT::on_reset()
 }
 
 
+
+void CHAT::con_say(void *result, void *user_data)
+{
+	((CHAT*)user_data)->say(0, console_arg_string(result, 0));
+}
+
+void CHAT::con_sayteam(void *result, void *user_data)
+{
+	((CHAT*)user_data)->say(1, console_arg_string(result, 0));
+}
+
+void CHAT::con_chat(void *result, void *user_data)
+{
+	const char *mode = console_arg_string(result, 0);
+	if(strcmp(mode, "all") == 0)
+		((CHAT*)user_data)->enable_mode(0);
+	else if(strcmp(mode, "team") == 0)
+		((CHAT*)user_data)->enable_mode(1);
+	else
+		dbg_msg("console", "expected all or team as mode");
+}
+
+void CHAT::on_init()
+{
+	MACRO_REGISTER_COMMAND("say", "r", con_say, this);
+	MACRO_REGISTER_COMMAND("say_team", "r", con_sayteam, this);
+	MACRO_REGISTER_COMMAND("chat", "s", con_chat, this);
+}
+
 bool CHAT::on_input(INPUT_EVENT e)
 {
 	if(mode == MODE_NONE)
@@ -63,8 +98,6 @@ void CHAT::on_message(int msgtype, void *rawmsg)
 	}
 }
 
-
-
 void CHAT::add_line(int client_id, int team, const char *line)
 {
 	current_line = (current_line+1)%MAX_LINES;
@@ -176,20 +209,6 @@ void CHAT::on_render()
 	gfx_text_color(1,1,1,1);
 }
 
-void con_chat(void *result, void *user_data)
-{
-	/*
-	const char *mode = console_arg_string(result, 0);
-	if(strcmp(mode, "all") == 0)
-		chat_enable_mode(0);
-	else if(strcmp(mode, "team") == 0)
-		chat_enable_mode(1);
-	else
-		dbg_msg("console", "expected all or team as mode");
-		*/
-}
-
-
 void CHAT::say(int team, const char *line)
 {
 	// send chat message
diff --git a/src/game/client/components/chat.hpp b/src/game/client/components/chat.hpp
index caec18b2..fc21ce1f 100644
--- a/src/game/client/components/chat.hpp
+++ b/src/game/client/components/chat.hpp
@@ -3,7 +3,6 @@
 
 class CHAT : public COMPONENT
 {
-public:
 	LINEINPUT input;
 	
 	enum 
@@ -34,6 +33,12 @@ public:
 
 	int mode;
 	
+	static void con_say(void *result, void *user_data);
+	static void con_sayteam(void *result, void *user_data);
+	static void con_chat(void *result, void *user_data);
+	
+public:
+	
 	void add_line(int client_id, int team, const char *line);
 	//void chat_reset();
 	//bool chat_input_handle(INPUT_EVENT e, void *user_data);
@@ -42,6 +47,7 @@ public:
 	
 	void say(int team, const char *line);
 	
+	virtual void on_init();
 	virtual void on_reset();
 	virtual void on_render();
 	virtual void on_message(int msgtype, void *rawmsg);