-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.cpp
More file actions
80 lines (68 loc) · 1.92 KB
/
Copy pathclient.cpp
File metadata and controls
80 lines (68 loc) · 1.92 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
#ifndef CALLGRAPH
#include <iostream>
#include <cassert>
#include "irc.h"
#include "args.h"
#endif
int main(int argc, char *argv[])
{
int numbytes;
char buf[MAXDATASIZE+1];
char line[MAXDATASIZE+1];
std::string port = std::string("6667");
ircb::args.parse(argc, argv);
std::shared_ptr<irc::connection> to = nullptr;
std::cout<<"Connecting to "<<ircb::args.serverName;
std::cout<<" on port "<<ircb::args.port<<" ... ";
std::cout<<std::endl<<std::endl;
try {
to = std::make_shared<irc::connection>(ircb::args.serverName,ircb::args.nickName,ircb::args.port);
}
catch(std::runtime_error &e){
std::cerr<<e.what()<<std::endl;
return -1;
}
std::cout<<"Handshake complete"<<std::endl;
std::string val;
int tok;
int joined = 0;
int pos=0;
do {
std::unique_ptr<irc::message> msg = to->next_msg();
// std::cout<<msg->toString();
/*
std::cout<<" SOURCE "<<msg->get_source();
std::cout<<" ";
std::cout<<" COMMAND "<<msg->get_command();
std::cout<<" ";
std::cout<<" PARAMS "<<msg->get_parameters();
std::cout<<std::endl;
std::string tmp_msg = msg->get_command();
tmp_msg.append(" ");
tmp_msg.append(msg->get_parameters());
*/
switch(msg->get_cmd()) {
default:
case 0:
//std::cout<<" +++ "<<msg->get_command()<<std::endl;
break;
case irc::PING:
to->pong(msg->get_parameters());
std::cout<<"PONG "<<msg->get_parameters()<<std::endl;
break;
case irc::CAP:
to->send_str("CAP END");
break;
case irc::INVITE:
to->join(msg->get_channel());
std::cout<<"Joined "<<std::endl;
break;
};
} while (1);
#ifdef _WIN64
closesocket(to->sockfd);
#else
close(to->sockfd);
#endif // _WIN64
return 0;
}