Subversion Repositories wimsdev

Rev

Rev 8185 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8185 Rev 12472
Line 23... Line 23...
23
{
23
{
24
}
24
}
25
 
25
 
26
void cmd_ping(char *p)
26
void cmd_ping(char *p)
27
{
27
{
28
    char *p1;
28
  char *p1;
29
    int qtest;
29
  int qtest;
30
    p1=find_word_start(p); *find_word_end(p1)=0;
30
  p1=find_word_start(p); *find_word_end(p1)=0;
31
    if(*p1!=0 && qbuf[0]!=0 && wordchr(qbuf,p1)!=NULL) qtest=1; else qtest=0;
31
  if(*p1!=0 && qbuf[0]!=0 && wordchr(qbuf,p1)!=NULL) qtest=1; else qtest=0;
32
    snprintf(textbuf+3,MAX_LINELEN,"%d %s\n%s",qtest,loadavg,ipbuf);
32
  snprintf(textbuf+3,MAX_LINELEN,"%d %s\n%s",qtest,loadavg,ipbuf);
33
}
33
}
34
 
34
 
35
void cmd_forklist(char *p)
35
void cmd_forklist(char *p)
36
{
36
{
37
    snprintf(textbuf+3,MAX_LINELEN,"%d",forkcnt);
37
  snprintf(textbuf+3,MAX_LINELEN,"%d",forkcnt);
38
}
38
}
39
 
39
 
40
void cmd_readfile(char *p)
40
void cmd_readfile(char *p)
41
{
41
{
42
    char *cut[2];
42
  char *cut[2];
43
    int l;
43
  int l;
44
    cutwords(p,cut,2);
44
  cutwords(p,cut,2);
45
    if(cut[1][0]) l=evalue(cut[1]); else l=MAX_LINELEN-16;
45
  if(cut[1][0]) l=evalue(cut[1]); else l=MAX_LINELEN-16;
46
    if(l<=0 || cut[0][0]==0) return;
46
  if(l<=0 || cut[0][0]==0) return;
47
    if(l>BUFFERLEN-16) l=BUFFERLEN-16;
47
  if(l>BUFFERLEN-16) l=BUFFERLEN-16;
48
    readfile(cut[0],textbuf+3,l);
48
  readfile(cut[0],textbuf+3,l);
49
}
49
}
50
 
50
 
51
void cmd_record(char *p)
51
void cmd_record(char *p)
52
{
52
{
53
    char *cut[2];
53
  char *cut[2];
54
    cutwords(p,cut,2);
54
  cutwords(p,cut,2);
55
    if(cut[1][0]==0) return;
55
  if(cut[1][0]==0) return;
56
    datafile_fnd_record(cut[1],atoi(cut[0]),textbuf+3);
56
  datafile_fnd_record(cut[1],atoi(cut[0]),textbuf+3);
57
}
57
}
58
 
58
 
59
void cmd_recordcnt(char *p)
59
void cmd_recordcnt(char *p)
60
{
60
{
61
    char *p1;
61
  char *p1;
62
    p1=find_word_start(p);
62
  p1=find_word_start(p);
63
    if(*p1==0) return;
63
  if(*p1==0) return;
64
    *find_word_end(p1)=0;
64
  *find_word_end(p1)=0;
65
    snprintf(textbuf+3,16,"%d",datafile_recordnum(p1));
65
  snprintf(textbuf+3,16,"%d",datafile_recordnum(p1));
66
}
66
}
67
 
67
 
68
struct cmdlist cmdlist[]={
68
struct cmdlist cmdlist[]={
69
        {"forkcnt",    cmd_forklist},
69
  {"forkcnt",    cmd_forklist},
70
        {"forkcount",    cmd_forklist},
70
  {"forkcount",    cmd_forklist},
71
        {"forklist",    cmd_forklist},
71
  {"forklist",    cmd_forklist},
72
        {"getscore",    cmd_getscore},
72
  {"getscore",    cmd_getscore},
73
        {"ping",    cmd_ping},
73
  {"ping",    cmd_ping},
74
        {"readfile",    cmd_readfile},
74
  {"readfile",    cmd_readfile},
75
        {"record",    cmd_record},
75
  {"record",    cmd_record},
76
        {"recordcnt",    cmd_recordcnt},
76
  {"recordcnt",    cmd_recordcnt},
77
        {"recordcount",    cmd_recordcnt},
77
  {"recordcount",    cmd_recordcnt},
78
        {"recordno",    cmd_recordcnt},
78
  {"recordno",    cmd_recordcnt},
79
        {"recordnum",    cmd_recordcnt},
79
  {"recordnum",    cmd_recordcnt},
80
        {"scorelog",    cmd_scorelog},
80
  {"scorelog",    cmd_scorelog},
81
        {"test",    cmd_test},
81
  {"test",    cmd_test},
82
};
82
};
83
int cmdcnt=(sizeof(cmdlist)/sizeof(cmdlist[0]));
83
int cmdcnt=(sizeof(cmdlist)/sizeof(cmdlist[0]));
84
 
84
 
85
void cmd(void)
85
void cmd(void)
86
{
86
{
87
    char *p1, *p2, cmdline[MAX_LINELEN+1];
87
  char *p1, *p2, cmdline[MAX_LINELEN+1];
88
    int i;
88
  int i;
89
 
89
 
90
    errno=0;
90
  errno=0;
91
    p1=find_word_start(textptr); p2=find_word_end(p1);
91
  p1=find_word_start(textptr); p2=find_word_end(p1);
92
    if(*p2) *p2++=0;
92
  if(*p2) *p2++=0;
93
    i=search_list(cmdlist,cmdcnt,sizeof(cmdlist[0]),p1);
93
  i=search_list(cmdlist,cmdcnt,sizeof(cmdlist[0]),p1);
94
    if(i<0) {sockerror(2,"bad_cmd %s",p1); return;}
94
  if(i<0) {sockerror(2,"bad_cmd %s",p1); return;}
95
    mystrncpy(cmdline,find_word_start(p2),sizeof(cmdline));
95
  mystrncpy(cmdline,find_word_start(p2),sizeof(cmdline));
96
    memmove(textbuf,"OK\n",4);
96
  memmove(textbuf,"OK\n",4);
97
    cmdlist[i].routine(cmdline);
97
  cmdlist[i].routine(cmdline);
98
}
98
}
99
 
99