Logo Search packages:      
Sourcecode: dctc version File versions  Download package

typical_action.c

/* DCTC - a Direct Connect text clone for Linux
 * Copyright (C) 2001 Eric Prevoteau
 *
 * typical_action.c: Copyright (C) Eric Prevoteau <www@a2pb.gotdns.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
/*
$Id: typical_action.c,v 1.8 2003/12/28 08:12:38 uid68112 Exp $
*/

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

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

#include "typical_action.h"
#include "dc_com.h"
#include "var.h"
#include "sema.h"

static GString *last_sent_myinfo=NULL;

/*********************************************************************/
/* setup our info on hub                                             */
/* string format:  $MyINFO $ALL nickname aaa$ $xxxf$bbb$yyy$         */
/*       aaa is user description                                     */
/*                xxx is connection type (ex: Cable)                          */
/*       f is a 1 byte flag. Default value: \x01                     */
/*             if not behind firewall, bit 1 must be set, else clear */
/*                bbb is e-mail (empty string)                                */
/*                yyy is size of shared data in bytes                         */
/*********************************************************************/
/* Note: the function may automatically add a TAG to the MyINFO */
/****************************************************************/
void set_user_info(int sck,char *nick, char *description, char *cnx,char cnx_opt,char *mail,double amount)
{
      GString *user_info;

      user_info=g_string_new("$MyINFO $ALL ");
      if((description_tag_auto==FALSE)&&(fake_dcpp_client==FALSE))
      {
            g_string_sprintfa(user_info,"%s %s$ $%s%c$%s$%.0lf$",
                                                            nick,
                                                            (description!=NULL)?description:"",
                                                            cnx,
                                                            cnx_opt,
                                                            (mail!=NULL)?mail:"",
                                                            amount+offset_sizeof_data);
      }
      else
      {
            int ttl_dl_slot;
            int busy_slot;

            get_ul_slot_values(bl_semid,&ttl_dl_slot,&busy_slot);

            if((fake_dcpp_client==FALSE)||(fake_dcpp_version==NULL)||(fake_dcpp_version->len==0))
            {
                  g_string_sprintfa(user_info,"%s %s <DCTC V:" VERSION ",M:%c,H:%d,S:%d>$ $%s%c$%s$%.0lf$",
                                                                  nick,
                                                                  (description!=NULL)?description:"",
                                                                  (behind_fw?'P':'A'),          /* automatically assign the letter according to the current FW mode */
                                                                  num_running_dctc(),           /* there is no way to know which DCTC runs with a registered user, report all running clients */
                                                                  ttl_dl_slot,
                                                                  cnx,
                                                                  cnx_opt,
                                                                  (mail!=NULL)?mail:"",
                                                                  amount+offset_sizeof_data);
            }
            else
            {
                  g_string_sprintfa(user_info,"%s %s <++ V:%s,M:%c,H:%d/0/0,S:%d>$ $%s%c$%s$%.0lf$",
                                                                  nick,
                                                                  (description!=NULL)?description:"",
                                                                  fake_dcpp_version->str,
                                                                  (behind_fw?'P':'A'),          /* automatically assign the letter according to the current FW mode */
                                                                  num_running_dctc(),           /* there is no way to know which DCTC runs with a registered user, report all running clients */
                                                                  ttl_dl_slot,
                                                                  cnx,
                                                                  cnx_opt,
                                                                  (mail!=NULL)?mail:"",
                                                                  amount+offset_sizeof_data);
            }
      }

      if(last_sent_myinfo!=NULL)
      {     /* a string already exist */
            if(strcmp(user_info->str,last_sent_myinfo->str))
            {     /* but it differs, so we must update it */
                  send_dc_line(sck,user_info->str,NULL);
                  last_sent_myinfo=g_string_assign(last_sent_myinfo,user_info->str);
            }
            g_string_free(user_info,TRUE);
      }
      else
      {     /* no previously sent myinfo */
            send_dc_line(sck,user_info->str,NULL);
            last_sent_myinfo=user_info;
      }
}

/****************************************************************/
/* this function must be called when the client is disconnected */
/* the hub to be sure when it re-enters, it sends its my info   */
/****************************************************************/
void reset_last_myinfo(void)
{
      if(last_sent_myinfo!=NULL)
            last_sent_myinfo=g_string_truncate(last_sent_myinfo,0);
}


Generated by  Doxygen 1.6.0   Back to index