aboutsummaryrefslogblamecommitdiff
path: root/src/espik_common_handler.c
blob: 27027ea4386781d477f98bac18fb61b2fe8f1ff8 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13




              







                      
                         



                                 
                        
 

                                                                   
 



                                      
 
                        
                             
      






                                         

                                     
                                                       
         
 
                   

 
                                                                    
 






























                                                                                  
                 
                                                   
      
                                     
                 
                                                  

                                     
 
                                          
                                      
 
                                        
 


                           
 
                   
 
/*
 *	DUDE !
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <Ecore.h>
#include <Ecore_Con.h>

#include "espik_global.h"
#include "espik_common_handler.h"
#include "espik_irc.h"
#include "espik_net.h"
#include "espik.h"
#include "espik_error.h"

int	server_data (void* data __UNUSED__, int ev_type __UNUSED__,
				Ecore_Con_Event_Server_Data* ev)
{
	unsigned int i;
	char*	msg;

	msg = strdup((char*)ev->data);

#if _ESPIK_DEBUG_	
	printf ("%s\n", msg);
#endif

	for (i=0 ; i < strlen(msg) ; i++)
	{
		if (msg[i] == ' ')
			msg[i] = '\0';
	}

	if (! (strcmp (msg, "PING")))
	{
		espik_raw_send ("PONG guybrush.melee");
	}

	return (0);
}

int	kb_get (void* data __UNUSED__, Ecore_Fd_Handler* fd_handler)
{
	char*	kb;
	char*	tmp;
	int		count;

	kb = malloc (sizeof (char) * 200);

	do
	{
		memset (kb, 0, 200);
		count = read (ecore_main_fd_handler_fd_get (fd_handler), kb, 198);

		if (count > 1)
		{
			del_backslash (kb);
			tmp = irc_send (kb);

			if (tmp)
			{
				espik_raw_send (tmp);
				free (tmp);
			}
		}
	}
	while (count >= 198);

	if (count == -1)
		perror ("read");

	if (count == 0)
	{
		tmp = irc_quit ("", "^D pressed");
#if _ESPIK_DEBUG_
		printf ("kb_get:\ntmp: %s\n", tmp);
#endif
		espik_raw_send (tmp);
#if _ESPIK_DEBUG_
		printf ("AFTER espik_raw_send\n");
#endif
		espik_raw_send (tmp);

/*		irc_disconnect();	*/
		espik_con_shutdown ();

		ecore_main_loop_quit ();

		free (tmp);
		return (0);
	}

	return (1);
}