-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
96 lines (88 loc) · 1.88 KB
/
Copy pathmain.cpp
File metadata and controls
96 lines (88 loc) · 1.88 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
#include "Server.hpp"
#include <unistd.h>
#include <csignal>
#include <cstring>
volatile sig_atomic_t ctrlc_pressed = 0;
bool isNumeric(char *str)
{
size_t i = 0;
while (str[i])
{
if (!isdigit(str[i]))
return false;
i++;
}
return true;
}
bool checkColumn(char *str)
{
int colonCount = 0;
for (int i = 0; str[i] != '\0'; ++i)
{
if (str[i] == ':') {
colonCount++;
}
}
if(colonCount != 2)
{
Debug::Error("Invalid use it should be \"./ircserv [host:port_network:password_network] <port> <password>\"");
std::exit(1);
return(false);
}
return(true);
}
int main(int argc, char **argv)
{
//Do parsing shit here
//check if port is valid
int port;
std::string pwd;
if (argc != 3)
{
Debug::Error("Invalid use it should be \"./ircserv <port> <password>\"");
std::exit(1);
}
else
{
port = atoi(argv[1]);
if(isNumeric(argv[1]) == false || port < 0 || port > 65535 )
{
Debug::Error("Invalid port");
std::exit(1);
}
pwd = argv[2];
char hostname[256];
if (gethostname(hostname, sizeof(hostname)) != 0)
{
Debug::Error("Invalid hostname");
std::exit(1);
}
Server irc(std::string(hostname), pwd , port);
}
// else if (argc == 4)
// {
// port = atoi(argv[2]);
// if(port < 0 || port > 65535 )
// {
// Debug::Error("Invalid server port");
// std::exit(1);
// }
// pwd = argv[3];
// checkColumn(argv[1]);
// char *token = strtok(const_cast<char*>(argv[1]), ":");
// std::string host = token;
// token = strtok(NULL, ":");
// int port_network = atoi(token);
// token = strtok(NULL, ":");
// std::string password_network = token;
// if(port_network < 0 || port_network > 65535 )
// {
// Debug::Error("Invalid network port");
// std::exit(1);
// }
// (void)port_network;
// (void)password_network;
// Server irc_argc4(host, pwd , port);
// }
return(0);
}