-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmtconv.c
More file actions
200 lines (179 loc) · 4.18 KB
/
Copy pathcmtconv.c
File metadata and controls
200 lines (179 loc) · 4.18 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#include <stdio.h>
#include <pthread.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <time.h>
#include <wchar.h>
#include <locale.h>
#include <dirent.h>
#include <sys/types.h>
#include <math.h>
#include <stdarg.h>
#define uchar unsigned char
#define ARTCODE unsigned int
#define CMTCODE unsigned char
#define BLOCKCODE char
//状态控制字
#define BUSY 1
#define READY 0
#define WAIT 1
#define NOTWAIT 0
//C0控制字
#define START 0xAA
//C1命令字
#define WFCM 100
#define LOGIN 101
#define REG 102
#define GTART 103
#define GTLST 104
#define ARTINI 105
#define DLART 106
#define ARTDAT 107
#define COMTUP 108
#define COMTDL 109
#define GTCMT 110
#define GTSTAT 111
#define STAT 112
#define SETSTAT 113
#define REQFO 114
#define REQDV 115
#define DV 116
#define DLCMT 117
#define MVART 118
#define ADLKE 119
//C1状态字
#define PWFAIL 200
#define USFAIL 201
#define REGSUCS 202
#define LOGSUCS 203
#define BNULL 204
#define BADCODE 205
#define DATSUCS 206
#define DATFAIL 207
#define REJ 208
#define ALIVE 222
//C2控制字
#define KEEP 0xDD
#define PARTEND 0xEE
#define STOP 0xFF
//参数控制
#define MAXCLNT 100
#define MAX_PATH_LEN 256
#define MAX_USERNAME_LEN 100
#define MAX_PASSWORD_LEN 100
#define PAKLEN 1024
#define MAX_TITLE_LEN 100
#define ROOT "/server/"
#define DB_ROOT "/server/db/"
#define CONFIG_ROOT "/server/config/"
#define LOG_PATH "/server/config/log/"
#define USER_PATH "/server/config/usr/"
#define USERLIST_PATH "/server/config/usr/userlist"
#define DV_PATH "/server/db/dv"
#define DV_ANN_PATH "/server/db/dv_ann"
struct User
{
char name[MAX_USERNAME_LEN];
char pw[MAX_PASSWORD_LEN];
unsigned int id;
};
struct Cmtdat
{
time_t time;
char maker[256];
int makerid;
char comment[784];
};
struct NewCmtdat
{
time_t time;
char maker[MAX_USERNAME_LEN];
int makerid;
char comment[921];
};
struct Artini
{
ARTCODE code;
BLOCKCODE bcode;
time_t time;
char title[MAX_TITLE_LEN];
char author[MAX_USERNAME_LEN];
char uploader[MAX_USERNAME_LEN];
int length;
char type;
int repcount;
int uploaderID;
char ori;
char isliked;
char empty2;
char empty3;
int like;
};
struct Servconf{
int maxc;
char reg;
char up;
char comt;
char refresh;
char log;
char fo;
char ann;
int checksum;
};
struct DailyVerse{
char content[821];
char author[100];
char source[100];
};
pthread_t clnt_thread[MAXCLNT]; //用户线程组
struct User clnt_users[MAXCLNT]; //连接对应账户组
int clnt_npthinfo = 0; //新线程附加信息暂存
int clnt_socks[MAXCLNT]; //用户套接字组
int clnt_stats[MAXCLNT]; //用户套接字状态
struct sockaddr_in clnt_addrs[MAXCLNT]; //用户地址组
socklen_t clnt_addr_sizes[MAXCLNT]; //用户地址大小组
int* clnt_writing[MAXCLNT]; //用户正在修改的文章
//全局设置
int conclnt = 0; //当前连接数int
int maxclnt = MAXCLNT; //最大连接数
char p_reg = 1; //允许注册
char p_log = 1; //允许登陆
char p_up = 1; //允许上传
char p_refresh = 1; //允许刷新
char p_fo = 1; //允许飞花令
char p_comt = 1; //允许评论
char p_ann = 0; //每日一句读取公告
char dic_stats[2] = {READY,READY};
char* DB_PATH[2] = {"/server/db/0/","/server/db/1/"};
char* DIC_PATH[2] = {"/server/db/_0dic","/server/db/_1dic"};
void inttostr(char* s,int l);
int main(void){
for(int a=0;a<2;++a){
FILE* dic = fopen(DIC_PATH[a],"rb+");
fseek(dic,0,SEEK_END);
int c = ftell(dic)/sizeof(struct Artini);
rewind(dic);
struct Artini list[c];
fread(list,sizeof(struct Artini),c,dic);
fclose(dic);
for(int i=0;i<c;++i){
char acodestr[11];
memset(acodestr,0,11);
inttostr(acodestr,list[i].code);
char cmtpath[MAX_PATH_LEN];
strcpy(cmtpath,DB_PATH[a]);
strcpy(cmtpath+strlen(cmtpath),acodestr);
strcpy(cmtpath+strlen(cmtpath),"/comment");
remove(cmtfile);
}
}
}
void inttostr(char* s,int l){
for(int i=0;i<10;i++)
s[i] = (l%(int)pow(10,10-i))/(int)pow(10,9-i) + 48;
s[11]=0;
}