3
#include <gtk/gtkplug.h>
5
#include <gaim/config.h>
6
#include <gaim/debug.h>
9
#include <gaim/gtkutils.h>
10
#include <gaim/gtkplugin.h>
11
#include <gaim/gtkconv.h>
12
#include <gaim/prefs.h>
13
#include <gaim/blist.h>
14
#include <gaim/gtkblist.h>
15
#include <gaim/signals.h>
16
#include <gaim/util.h>
17
#include <gaim/internal.h>
18
#include <gaim/cmds.h>
19
#include <gaim/debug.h>
20
#include <gaim/plugin.h>
21
#include <gaim/version.h>
27
#define HEADER "*** Command from the gaim-ggz plugin:"
29
#define GGZWRAPPER "ggz-wrapper"
30
#define GGZMODULECONFIG "/home/ggz/BUILD/etc/ggz.modules"
31
#define SERVER "live.ggzgamingzone.org"
33
GaimCmdRet commande(GaimConversation *conv, const gchar *cmd, gchar **args, gchar **error, void *data) {
37
joueur=g_strdup_printf("host%d", (int) (999.0*rand()/(RAND_MAX+1.0)));
38
for(argc=0;args[argc];argc++);
41
*error=g_strdup("Il faut spécifier un jeu, les jeux possibles sont(respectez la casse):\n-TicTacToe\n-Reversi\n-Chess");
42
return GAIM_CMD_RET_FAILED;
47
char **parms=malloc(4*sizeof(char *));
51
sys_parm=g_strdup_printf("%s -u %s -g %s -s %s", GGZWRAPPER, parms[0], parms[1], SERVER);
56
printf("LAUNCH: %s,%s %s %s\n", "/bin/sh", parms[0], parms[1], parms[2]);
57
execv("/bin/sh", parms);
60
gaim_conv_im_send(GAIM_CONV_IM(conv), g_strdup_printf("%s%s %s %s", HEADER, jeu,joueur, FOOTER));
61
return GAIM_CMD_RET_OK;
64
*error=strdup("Probleme de fork()");
65
return GAIM_CMD_RET_FAILED;
69
gboolean icon_clicked(void **arg, GdkEvent *ev) {
70
if(ev->type==GDK_BUTTON_PRESS) {
71
GaimConversation *conv=arg[0];
72
char **args=malloc(2*sizeof(char*));
75
commande(conv, g_strdup("jeu"), args, NULL, NULL);
81
gboolean PopMenu(GtkMenu *menu, GdkEvent *ev) {
82
if(ev->type==GDK_BUTTON_PRESS) {
83
GdkEventButton *bev=(GdkEventButton *)ev;
84
gtk_menu_popup(menu, NULL, NULL, NULL, NULL, bev->button, bev->time);
90
static void nouvelle_convers(GaimConversation *conv, void *data) {
91
// printf("Une nouvelle conversation:%s!!\n", gaim_conversation_get_name(conv));
92
GaimGtkConversation *gtkconv=GAIM_GTK_CONVERSATION(conv);
93
GtkWidget *bbox=gtkconv->bbox;
107
GtkIconFactory *factory;
109
factory = gtk_icon_factory_new();
110
gtk_icon_factory_add_default(factory);
112
pixbuf = gdk_pixbuf_new_from_xpm_data(ggz_xpm);
113
iconset = gtk_icon_set_new_from_pixbuf(pixbuf);
114
g_object_unref(G_OBJECT(pixbuf));
115
gtk_icon_factory_add (factory, "ggzicon", iconset);
117
sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
119
icon = gaim_gtkconv_button_new("ggzicon", "Play Game", "Pfff", gtkconv->tooltips, GTK_SIGNAL_FUNC(PopMenu), NULL);
128
menu = gtk_menu_new();
130
handle = ggz_conf_parse(GGZMODULECONFIG, GGZ_CONF_RDONLY);
131
ret = ggz_conf_read_list(handle, "Games", "*Engines*", &argcp, &argvp);
132
for(i = 0; i < argcp; i++)
135
arg = malloc(sizeof(void*)*2);
136
arg[0] = (gpointer)conv;
137
arg[1] = strdup(gamename);
138
menuitem = gtk_menu_item_new_with_label(gamename);
139
gtk_signal_connect_object(GTK_OBJECT(menuitem), "event", GTK_SIGNAL_FUNC(icon_clicked), (gpointer) arg);
140
gtk_menu_append(GTK_MENU(menu), menuitem);
141
gtk_widget_show(menuitem);
143
ggz_conf_close(handle);
146
gtk_signal_connect_object(GTK_OBJECT(icon), "event", GTK_SIGNAL_FUNC(PopMenu), GTK_OBJECT(menu));
149
gtk_box_pack_start(GTK_BOX(bbox), icon, FALSE, FALSE, 0);
150
gtk_button_set_relief(GTK_BUTTON(icon), GTK_RELIEF_NONE);
151
gtk_tooltips_set_tip(gtkconv->tooltips, icon, g_strdup("Clickez sur ce bouton pour jouer avec votre correspondant"), 0);
152
g_hash_table_insert(conv->data, g_strdup("icon"), icon);
153
gtk_size_group_add_widget(sg, icon);
154
gtk_box_reorder_child(GTK_BOX(bbox), icon, 7);
156
gtk_widget_show(icon);
159
static void message_recu(GaimAccount *acct,char **sender, char **buffer,int flags, void *data) {
160
printf("Recu un message de %s:%s\n", *sender, *buffer);
164
static void message_recu2(GaimAccount *acct,char **sender, char **buffer,int flags, GaimConversation *conv,void *data) {
165
// printf("Recu un message de %s:%s\n", *sender, *buffer);
170
if(strstr(*buffer, HEADER)==NULL)
174
jeu=strstr(*buffer, HEADER);
176
jeu[strlen(jeu)-strlen(strstr(jeu, FOOTER))]='\0';
177
joueur=index(jeu, ' ');
179
printf("Pas de joueur mais un jeu: %s\n", jeu);
184
if(index(joueur, ' ')) {
185
joueur[strlen(joueur) - strlen(index(joueur, ' '))]='\0';
190
//L'enfant trop fort hein :)
191
char **parms=malloc(4*sizeof(char *));
193
parms[1]=g_strdup_printf("guest%d", (int) (999.0*rand()/(RAND_MAX+1.0)));
195
sys_parm=g_strdup_printf("%s -u %s -d %s -g %s -s %s", GGZWRAPPER, parms[1], parms[2], jeu, SERVER);
200
printf("LAUNCH: %s,%s %s %s\n", "/bin/sh", parms[0], parms[1], parms[2]);
201
execv("/bin/sh", parms);
204
//Ici c'est le pere je vous apprends beaucoup de choses non? ;)
206
//Ici c'est quand y a eu une erreur........
208
//Ca sert a rien d'afficher ce somtueux message ;)
213
plugin_load(GaimPlugin *plugin)
215
// gaim_debug(GAIM_DEBUG_INFO, "simple", "simple plugin loaded.\n");
217
void *conv_handle = gaim_conversations_get_handle();
218
gaim_signal_connect(conv_handle, "conversation-created",
219
plugin, GAIM_CALLBACK(nouvelle_convers), NULL);
220
gaim_signal_connect(conv_handle, "receiving-chat-msg",
221
plugin, GAIM_CALLBACK(message_recu), NULL);
222
gaim_signal_connect(conv_handle, "receiving-im-msg",
223
plugin, GAIM_CALLBACK(message_recu2), NULL);
224
gaim_cmd_register("jeu", "w", GAIM_CMD_P_PLUGIN, GAIM_CMD_FLAG_IM|GAIM_CMD_FLAG_ALLOW_WRONG_ARGS, NULL, GAIM_CMD_FUNC(commande), "jeu <Le nom du jeu>",NULL);
229
plugin_unload(GaimPlugin *plugin)
231
// gaim_debug(GAIM_DEBUG_INFO, "simple", "simple plugin unloaded.\n");
236
static GaimPluginInfo info =
238
//GAIM_PLUGIN_API_VERSION, /**< api_version */
242
GAIM_PLUGIN_STANDARD, /**< type */
243
GAIM_GTK_PLUGIN_TYPE, /**< ui_requirement */
245
NULL, /**< dependencies */
246
GAIM_PRIORITY_DEFAULT, /**< priority */
249
"GGZ for gaim", /**< name */
250
VERSION, /**< version */
252
"To have ggz in gaim.",
254
"Tests to see that most things are working.",
255
"Husson Pierre-Hugues <phh@www.phh.sceen.net>", /**< author */
256
"http://www.phh.sceen.net", /**< homepage */
258
plugin_load, /**< load */
259
plugin_unload, /**< unload */
260
NULL, /**< destroy */
262
NULL, /**< ui_info */
263
NULL /**< extra_info */
269
init_plugin(GaimPlugin *plugin)
273
GAIM_INIT_PLUGIN(ggz4gaim, init_plugin, info)