forked from sejinRyu/Chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatServer.cpp
More file actions
81 lines (78 loc) · 2.43 KB
/
ChatServer.cpp
File metadata and controls
81 lines (78 loc) · 2.43 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
#include "TcpSocket.h"
#include "UserManagement.h"
#include <mysql++/mysql++.h>
#include <mysql++/result.h>
#include <vector>
using namespace std;
int main(int argc,char** argv)
{
try
{
ServerTcpSocket server;
while(server.accept()>0)
{
pid_t pid;
if((pid=fork())==0)
{
cout<<"connect!"<<endl;
UserManagement user(server,"chatserver","10.156.145.48","root","shangus1");
while(1)
{
int uuid=atoi(server.receive(23).c_str());
if(uuid==0)//login
user.login();
else if(uuid==1)//add user
user.join();
else if(uuid==2)//delete user //edit need //secure
user.withdraw();
else if(uuid==3)//search ID -> send List
user.searchID();
else if(uuid==4)//add friends //edit need //nothing account
user.addFriend();
else if(uuid==5)//friends list ->vector ->send
user.myFriendsList();
else if(uuid==6)//delete friend
user.deleteFriend();
else if(uuid==7)//make chatroom
user.makeChatRoom();
else if(uuid==8)
user.logout();
/*else //echo
{
pid_t pid1=fork();
string tmp;
while(1)
{
if(pid1>0)
{
tmp=server.receive(key);
cout<<tmp<<endl;
}
else
{
cin>>tmp;
server.send(tmp,key);
}
}
}*/
}
}
wait(0);
}
}
catch (mysqlpp::BadQuery& e)
{
cerr << "BadQuery : " << e.what() << endl;
cerr<<e.errnum()<<endl;
}
catch(const char* e)
{
perror(e);
}
catch(UserManagement::Flag e)
{
if(e==UserManagement::end)
exit(1);
}
return 0;
}