/* * PSYC Manager Daemon, src/msg.cc * Copyright (C) 2001 Mark Ralf Thomson * Concept: Mark Ralf Thomson */ #include "psycm.h" #include "net.h" #include "classes.h" #include "extern.h" #include "msg.h" #include "user.h" /* TODO: algorithim that makes a psyc packet (mkpacket) including langugae specific translation and longform parameters translation to tokenized form alg. must have easy (and tricky :) structure and handling */ // PSYC commands message comtab[] = { {"login",m_ulogin,6,"A",0}, }; params paratab[] = { //{PL_MESSAGE,PT_MESSAGE}, fehler bei der initalisierung :-( //{PL_NOTICE,PT_NOTICE}, //{PL_NICK,PT_NICK}, //{PL_NAME,PT_NAME}, }; char LEER[] =""; // PSYC Longform to tokenized form int short2long(char *in, char*out) { int i=0,i2=0,len=0; char temp[LINELEN]; params **temp2; while(in[i] != '\0') { if(in[i] >= 56 && in[i] <= 122) temp[i2++] = in[i]; else return -1; if (i > 8) return -2; if(in[i] == '_' || in[i] == '\0') { temp[i2] = '\0'; if((temp2 = pa.find(temp)) == NULL) return -1; strcat(out,(*temp2)->para); len = strlen(out); strncat(out,in+i,LINELEN - len); return 0; } i++; } return 0; } int long2short(char *in) { int i=0; char temp[LINELEN]; char out[LINELEN]; char *temp3; params **temp2; for (i=0; i<=9; i++) { if((temp2 = pa.find(in))) { strcat(out,(*temp2)->token); } else { temp3 = strrchr(in,'_'); if(temp3 != NULL) { strcat(temp,temp3); temp3[0] = '\0'; } else return -1; } } strcpy(in,out); strcat(in,temp); return 0; } /* atoi transformates an integer to an ascii char (0 - 99'999) */ void itoa (char *array, unsigned int zahl) { int teiler; int j = 0; bool ok = false; int prefix = 0; for (teiler = 10000; teiler >= 1; teiler = teiler / 10) { prefix = zahl / teiler; if (ok == false && prefix != 0) ok = true; if (ok) { array[j] = (48 + prefix); j++; } zahl = zahl % teiler; } array[j+1]=(char)NULL; } void init_params () { int o; for (o = 0; o <= CURPARA; o++) { pa.insert (paratab[o].para, ¶tab[o]); pa.insert (paratab[o].token, ¶tab[o]); } } void init_coms () { int o; for (o = 0; o <= CURCOM; o++) { cm.insert (comtab[o].cmd, &comtab[o]); cm.insert (comtab[o].token, &comtab[o]); } }