File: xIrcCommands.cpp

package info (click to toggle)
xirc 2.0-3
  • links: PTS
  • area: contrib
  • in suites: hamm, slink
  • size: 2,624 kB
  • ctags: 2,093
  • sloc: cpp: 21,094; makefile: 1,033
file content (154 lines) | stat: -rw-r--r-- 3,183 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/***************************************************************************
**    xIrcCommands.cpp  $Revision: 1.7 $ - $Name: V2-0 $ 
**    Class for handling IRC Commands
**
** Copyright (C) 1995, 1996  Joseph Croft <jcroft@unicomp.net>  
** 
** 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 1, 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., 675 Mass Ave, Cambridge, MA 02139, USA.
**
 ***************************************************************************/
#include <stdio.h>
#include "strings.h"
#include "ctype.h"
#include "xIrcCommands.h"

xIrcCommands ircResponses;

typedef struct
{
   int      code;
   char     *text;
} xIrcResponse;

typedef struct
{
   char     *cmd;
   int      *usrFlag;
   char     *text;
} xIrcCmd;

static xIrcResponse rspList[] =
{
   { 301, "Away: " },
   { 324, "Channel Mode: " },
   { 331, "" },
   { 332, "Topic: " },
   { 333, "Channel Creator: " },
   { 341, "Inviting: " },
   { 353, "Channel Members: " },
   { 367, "Banned: " },
   { 0, "" }
};

//
// This is an array of Response strings that can be recieved
// from the server. It must stay in synch with the values set
// in the include file!!
//
static char *commandList[] = 
{
   "AWAY",
   "INVITE",
   "JOIN",
   "KICK",
   "LIST",
   "MODE",
   "NAMES",
   "NICK",
   "NOTICE",
   "PART",
   "PING",
   "PONG",
   "PRIVMSG",
   "QUIT",
   "TOPIC",
   "VERSION",
   "WHO",
   "WHOIS",
   "WHOWAS",
   "FLUSH",
   "NOTE",
   "LINKS",
   "MAP",
   NULL
};

static char emptyStr[] = "";
static QString tmpStr;

xIrcCommands::xIrcCommands()
{
   commandList = ::commandList;
}

int xIrcCommands::code(const char *pCmd)
{
   char buf[20], *cp;
   int x, rv;
   
   for (x = 0, cp = buf; *pCmd && x < 20; x++, pCmd++)
   {
      *(cp++) = toupper(*pCmd);
      *cp = '\0';
   }
   
   for (x = 0; commandList[x] != NULL; x++)
   {
      if (strcmp(commandList[x], buf) == 0)
         break;
   }
   if (commandList[x] != NULL)
      rv = x + IRCRESP_First;
   else
      rv = IRCRESP_Unknown;
   return(rv);
}

char *xIrcCommands::name(int cmd)
{
   char *rv;
   int x;
   
   if ((cmd -= IRCRESP_First) >= 0)
   {
      for (x = 0; commandList[x] != NULL && x < cmd; x++);
   
      if (x == cmd)
         rv = commandList[x];
      else
         rv = emptyStr;
   }
   else
      rv = emptyStr;
   return(rv);
}

const char *xIrcCommands::text(int cmd)
{
   const char *rv;
   char buf[80];
   int x;

   for (x = 0; rspList[x].code != cmd && rspList[x].code != 0; x++);
   if (rspList[x].code != 0)
      rv = rspList[x].text;
   else
   {
      sprintf(buf, "%d::", cmd);
      tmpStr = buf;
      rv = tmpStr;
   }
   return(rv);
}