Q&D Hack for Action (/me) Support in teg
Andreas Pickart
dev at apic.name
Sun Jun 30 16:02:47 UTC 2013
Hi,
first of all Thanks for maintaining this really epic Game.
I missed the obligatory /me Command in Chat and Q&D-copypasted a Hack
to support it.
Would be cool if You could adopt it in the next Version. ;-)
So long.
Andreas Pickart aka Apic
--8<-- Patch follows -->8---
diff -ur teg-0.11.2+debian/client/globals.h action-0.11.2+debian/client/globals.h
--- teg-0.11.2+debian/client/globals.h 2008-06-09 08:09:44.000000000 +0200
+++ action-0.11.2+debian/client/globals.h 2013-06-23 14:47:09.000000000 +0200
@@ -64,6 +64,7 @@
GUI_WINNER, /**< un player gano */
GUI_MISSION, /**< muestra tu mission */
GUI_TEXTPLAYERMSG, /**< mensaje de un player */
+ GUI_TEXTPLAYERACT, /**< action de un player */
GUI_LAST /**< este no existe */
};
@@ -96,6 +97,7 @@
extern TEG_STATUS gui_winner(int numjug, int mission);
extern TEG_STATUS gui_mission();
extern TEG_STATUS gui_textplayermsg(char *n,int nj, char *m );
+extern TEG_STATUS gui_textplayeract(char *n,int nj, char *m );
extern TEG_STATUS gui_scores(void);
typedef struct _cgame {
diff -ur teg-0.11.2+debian/client/gui-gnome/chatline.c action-0.11.2+debian/client/gui-gnome/chatline.c
--- teg-0.11.2+debian/client/gui-gnome/chatline.c 2008-06-09 08:09:43.000000000 +0200
+++ action-0.11.2+debian/client/gui-gnome/chatline.c 2013-06-23 14:53:46.000000000 +0200
@@ -55,7 +55,11 @@
theinput = gtk_entry_get_text(w);
if(*theinput) {
- if(theinput[0]=='/') {
+ if(theinput[0]=='/' && tolower(theinput[1])=='m' && tolower(theinput[2])=='e' && isspace(theinput[3])) {
+ char *d = g_strdup(theinput);
+ out_mensaje( d );
+ g_free(d);
+ } else if(theinput[0]=='/') {
net_printf( g_game.fd, "%s\n",&theinput[1]);
} else {
char *d = g_strdup(theinput);
@@ -96,6 +100,41 @@
name[sizeof(name)-1] = 0;
gtk_text_buffer_get_end_iter(buffer, &iter);
+
+ ptr_name = translate_to_utf8( name );
+ ptr_msg = translate_to_utf8( msg );
+
+ if( gui_private.msg_show_colors) {
+ gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, ptr_name, -1, get_tag_for_color(num), NULL);
+ } else {
+ gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, " ", -1, get_tag_for_color(num), NULL);
+ gtk_text_buffer_insert(buffer, &iter, ptr_name, -1);
+ }
+ gtk_text_buffer_insert(buffer, &iter, " ", -1);
+ gtk_text_buffer_insert(buffer, &iter, ptr_msg, -1);
+ gtk_text_buffer_insert(buffer, &iter, "\n", -1);
+
+
+ free( ptr_name );
+ free( ptr_msg );
+
+
+ update_scrollbar( buffer );
+
+ return TEG_STATUS_SUCCESS;
+}
+
+TEG_STATUS gui_textplayeract(char *n, int num, char *msg)
+{
+ GtkTextIter iter;
+ char name[PLAYERNAME_MAX_LEN+30];
+ GtkTextBuffer *buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(main_message_area) );
+ gchar *ptr_name, *ptr_msg;
+
+ snprintf(name,sizeof(name)-1,"* %s ",n);
+ name[sizeof(name)-1] = 0;
+
+ gtk_text_buffer_get_end_iter(buffer, &iter);
ptr_name = translate_to_utf8( name );
ptr_msg = translate_to_utf8( msg );
diff -ur teg-0.11.2+debian/client/gui-null/null.c action-0.11.2+debian/client/gui-null/null.c
--- teg-0.11.2+debian/client/gui-null/null.c 2008-06-09 08:09:44.000000000 +0200
+++ action-0.11.2+debian/client/gui-null/null.c 2013-06-23 14:43:52.000000000 +0200
@@ -113,3 +113,7 @@
{
return TEG_STATUS_SUCCESS;
}
+TEG_STATUS gui_textplayeract(char *n,int nj, char *m );
+{
+ return TEG_STATUS_SUCCESS;
+}
diff -ur teg-0.11.2+debian/client/gui-sdl/gui.c action-0.11.2+debian/client/gui-sdl/gui.c
--- teg-0.11.2+debian/client/gui-sdl/gui.c 2008-06-09 08:09:43.000000000 +0200
+++ action-0.11.2+debian/client/gui-sdl/gui.c 2013-06-23 14:49:41.000000000 +0200
@@ -197,6 +197,10 @@
{
return TEG_STATUS_SUCCESS;
}
+TEG_STATUS gui_textplayeract(char *n,int nj, char *m )
+{
+ return TEG_STATUS_SUCCESS;
+}
TEG_STATUS gui_country_select(int country)
{
return TEG_STATUS_SUCCESS;
diff -ur teg-0.11.2+debian/client/inputfd.c action-0.11.2+debian/client/inputfd.c
--- teg-0.11.2+debian/client/inputfd.c 2008-06-09 08:09:43.000000000 +0200
+++ action-0.11.2+debian/client/inputfd.c 2013-06-23 14:46:34.000000000 +0200
@@ -33,6 +33,7 @@
TEG_STATUS clitok_playerid(char *str);
TEG_STATUS clitok_newplayer(char *str);
TEG_STATUS clitok_message(char *str);
+TEG_STATUS clitok_action(char *str);
TEG_STATUS clitok_countries(char *str);
TEG_STATUS clitok_fichas(char *str);
TEG_STATUS clitok_fichas2(char *str);
@@ -74,6 +75,7 @@
{ TOKEN_PLAYERID, clitok_playerid },
{ TOKEN_NEWPLAYER, clitok_newplayer},
{ TOKEN_MESSAGE, clitok_message },
+ { TOKEN_ACTION, clitok_action },
{ TOKEN_COUNTRIES, clitok_countries },
{ TOKEN_FICHAS, clitok_fichas },
{ TOKEN_FICHAS2, clitok_fichas2 },
@@ -971,6 +973,42 @@
}
return TEG_STATUS_SUCCESS;
error:
+ textmsg(M_ERR,"Error in clitok_message()");
+ return TEG_STATUS_ERROR;
+}
+
+/* a new action message has arrived */
+TEG_STATUS clitok_action( char *str)
+{
+ char name[PLAYERNAME_MAX_LEN];
+ int numjug;
+ PARSER p;
+ DELIM igualador={ ':', ':', ':' };
+ DELIM separador={ ',', ',', ',' };
+
+ if( strlen(str) == 0 )
+ goto error;
+
+ p.igualador = &igualador;
+ p.separador = &separador;
+ p.data = str;
+
+ if( parser_call( &p ) && p.hay_otro ) {
+ strncpy( name, p.token, sizeof(name)-1);
+ name[sizeof(name)-1]=0;
+ } else goto error;
+
+ if( parser_call( &p ) && p.hay_otro ) {
+ numjug = atoi( p.token );
+ } else goto error;
+
+ /* I dont care if there is one more or not */
+
+ if( g_game.msg_show & M_MSG ) {
+ gui_textplayeract(name,numjug,p.data);
+ }
+ return TEG_STATUS_SUCCESS;
+error:
textmsg(M_ERR,"Error in clitok_message()");
return TEG_STATUS_ERROR;
}
diff -ur teg-0.11.2+debian/common/protocol.h action-0.11.2+debian/common/protocol.h
--- teg-0.11.2+debian/common/protocol.h 2008-06-09 08:09:44.000000000 +0200
+++ action-0.11.2+debian/common/protocol.h 2013-06-23 14:39:01.000000000 +0200
@@ -39,6 +39,7 @@
#define TOKEN_HELP "help"
#define TOKEN_LOST "loser"
#define TOKEN_MESSAGE "msg"
+#define TOKEN_ACTION "action"
#define TOKEN_PLAYERID "player_id"
#define TOKEN_RECONNECT "reconnect"
#define TOKEN_NEWPLAYER "newplayer"
diff -ur teg-0.11.2+debian/intltool-update action-0.11.2+debian/intltool-update
diff -ur teg-0.11.2+debian/robot/gui.c action-0.11.2+debian/robot/gui.c
--- teg-0.11.2+debian/robot/gui.c 2008-06-09 08:09:44.000000000 +0200
+++ action-0.11.2+debian/robot/gui.c 2013-06-23 14:51:33.000000000 +0200
@@ -78,6 +78,22 @@
return TEG_STATUS_SUCCESS;
}
+TEG_STATUS gui_textplayeract(char *n, int num, char *msg)
+{
+ char converted[sizeof(g_game.myname)+1];
+
+ memset( converted,0,sizeof(converted));
+
+ tolowerstr(msg,msg);
+ tolowerstr(_(g_game.myname), converted);
+
+ /* a player, not a robot, sends me a message i respond */
+ if( strstr(msg,converted ) && ai_findname(n) != TEG_STATUS_SUCCESS ) {
+ ai_msg( AI_MSG_ANSWER, n );
+ }
+ return TEG_STATUS_SUCCESS;
+}
+
TEG_STATUS gui_habilitado( int numjug )
{
PCPLAYER pJ;
More information about the Pkg-games-devel
mailing list