-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSini.cpp
More file actions
160 lines (145 loc) · 4.33 KB
/
Copy pathSini.cpp
File metadata and controls
160 lines (145 loc) · 4.33 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
#include <stdio.h>
#include "sini_io.h"
#include <string.h>
#include "sini_server.h"
#include "sini_socket.h"
#include "sini_client.h"
#include "sini_config.h"
#include <stdlib.h>
int main(int argc, char* argv[])
{
char Name[256];
char IPBuffer[16];
if (!sini_sockinit())
{
printf( "Error while initializing Sockets\n" );
return 0;
}
sini_ioinit();
sini_printf( "Welcome to Sini 1.6 from ***Zebr@XXL***!!!\n" );
sini_printf( " Enter \".help\" to view list of all commands\n" );
LoadConfig();
const char *InCongigName = GetNameFromConfig();
if (InCongigName)
strcpy( Name, InCongigName );
else
{
sini_namedread( "Input your name:", Name, 256 );
SetNameInConfig( Name );
}
if (strcmp( Name, "***Zebr@XXL***" ) == 0) sini_printf( "Wow. My creator with me!!!\n" );
sini_namedread( "Input server IP, .list, or blank for server creation:", IPBuffer, 16 );
if (strcmp( IPBuffer, ".list" ) == 0)
{
PrintServerList();
sini_namedread( "Input server IP or id, or blank for server creation:", IPBuffer, 16 );
if (IPBuffer[0] != 0)
{
if (sini_parseip( IPBuffer ) == 0)
{
int id = atoi( IPBuffer );
CopyIPFromID( id, IPBuffer );
}
}
}
ClearServersList();
if (IPBuffer[0] == 0)
{
strcpy( IPBuffer, "127.0.0.1" );
if (!CreateServer())
{
sini_printf( "Error while creating server\n" );
sini_sockdelete();
return 0;
}
}
if (!CreateClient( IPBuffer, Name ))
{
sini_printf( "Error while connecting to server\n" );
CloseServer();
sini_sockdelete();
return 0;
}
bool Running = true;
char MessageBuffer[2048];
while (Running)
{
sini_namedread( ">", MessageBuffer, 2048, false );
if (MessageBuffer[0] == '.')
{
if (strcmp( &MessageBuffer[1], "exit" ) == 0)
{
Running = false;
continue;
}else if (strcmp( &MessageBuffer[1], "list" ) == 0)
{
ClientPrintList();
continue;
}else if (memcmp( &MessageBuffer[1], "name", 4 ) == 0)
{
int pos = 0;
while (MessageBuffer[pos] != ' ') pos++;
while (MessageBuffer[pos] == ' ') pos++;
ClientChangeName( &MessageBuffer[pos] );
SetNameInConfig( &MessageBuffer[pos] );
continue;
}else if ((memcmp( &MessageBuffer[1], "password", 4 ) == 0)
||(memcmp( &MessageBuffer[1], "pass", 4 ) == 0))
{
int pos = 0;
while (MessageBuffer[pos] != ' ') pos++;
while (MessageBuffer[pos] == ' ') pos++;
AddPassword( &MessageBuffer[pos] );
continue;
}else if (strcmp( &MessageBuffer[1], "help" ) == 0)
{
sini_printf( "Sini help:\n");
sini_printf( " .exit - exit from Sini\n");
sini_printf( " .list - show who online\n");
sini_printf( " .name [new_name] - change name to [new_name]\n");
sini_printf( " .pass [password] - set server password to [password]\n");
sini_printf( " .help - show this message\n");
sini_printf( " .showtime - show time when message was sended\n");
sini_printf( " .hidetime - hide time when message was sended\n");
sini_printf( " .info - show information about online peoples\n");
sini_printf( "Special symbols:\n");
sini_printf( " \\\\ = '\\'\n");
sini_printf( " \\w = '\x02'\n");
sini_printf( " \\b = '\x01'\n");
sini_printf( " \\h = '\x03'\n");
sini_printf( " \\r = '\x04'\n");
sini_printf( " \\+ = '\x05'\n");
sini_printf( " \\p = '\x06'\n");
sini_printf( " \\m = '\x0b'\n");
sini_printf( " \\g = '\x0c'\n");
sini_printf( " \\s = '\x0e'\n");
sini_printf( " \\* = '\x0f'\n");
continue;
}else if (strcmp( &MessageBuffer[1], "showtime" ) == 0)
{
SetShowTime( true );
continue;
}else if (strcmp( &MessageBuffer[1], "hidetime" ) == 0)
{
SetShowTime( false );
continue;
}else if (strcmp( &MessageBuffer[1], "info" ) == 0)
{
PrintServerInfo();
continue;
}else if (memcmp( &MessageBuffer[1], "serv_name", 4 ) == 0)
{
int pos = 0;
while (MessageBuffer[pos] != ' ') pos++;
while (MessageBuffer[pos] == ' ') pos++;
SetServerName( &MessageBuffer[pos] );
continue;
}
}
ClientSendTextMessage( MessageBuffer );
}
CloseClient();
CloseServer();
sini_sockdelete();
return 0;
}