Newer
Older
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
/*
This file is part of SLC.
Copyright (C) 2008 Sebastien LUTTRINGER <contact@seblu.net>
SLC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
SLC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with SLC; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "slc.hh"
#include "engine.hh"
#include "screen.hh"
#include "options.hh"
#include "sll/connection.hh"
namespace cmd {
/*!
** Exec command if @param s is not a command.
*/
void exec(const char *s) {
// string is a local command
if (*s == '/') {
if (!strcmp(s, "/exit")) {
S << INF_DATA << "Exiting.\n";
exit(0);
}
else if (!strcmp(s, "/logout"))
cmd::logout();
else if (!strcmp(s, "/login"))
cmd::login();
else if (!strcmp(s, "/help"))
cmd::help();
else if (!strncmp(s, "/user", 5))
cmd::user(s);
else if (!strncmp(s, "/pass", 5))
cmd::pass(s);
else
S << WAR_DATA << s << ": Unkown command.\n";
}
// String is a remote command
else {
if (C.connected()) {
C.sendln(s);
S << ">> " << s << "\n";
}
else
S << "Unable to send: " << s << ". Try to connect with /login !\n";
}
}
/**
* Log into server
*
*/
void login() {
if (C.connected()) {
S << INF_DATA << "Already connected. Please disconnect before.\n";
return;
}
S << INF_DATA << "Login.\n";
E.login();
}
/**
* Log out of server
*
*/
void logout() {
if (!C.connected()) {
S << INF_DATA << "Not connected. Please connect before.\n";
return;
}
S << INF_DATA << "Logout.\n";
C.disconnect();
}
/**
* Print cmd help
*
*/
void help() {
S << INF_DATA << "Commands:\n";
S << INF_DATA << "/exit: Quit.\n";
S << INF_DATA << "/login: Connect and try to login on server.\n";
S << INF_DATA << "/logout: Disconnect from server.\n";
S << INF_DATA << "/user <name>: Change username.\n";
S << INF_DATA << "/pass <pass>: Change password.\n";
S << INF_DATA << "/help: Print this help.\n";
}
/**
* Change user name to @param s
*/
void user(const char *s) {
if (C.connected()) {
S << INF_DATA << "Your are connected. Please deconnect before.\n";
return;
}
// extract name
string login = s;
login.erase(0, 6);
if (login.empty()) {
S << WAR_DATA << "Empty username.\n";
return;
}
// set new name
O.login = login;
// display
S << INF_DATA << "Username changed to `" << O.login << "'.\n";
}
/**
* Change pass name @param s
*/
void pass(const char *s) {
if (C.connected()) {
S << INF_DATA << "Your are connected. Please deconnect before.\n";
return;
}
// extract name
string pass = s;
pass.erase(0, 6);
if (pass.empty()) {
S << WAR_DATA << "Empty password.\n";
return;
}
// set new name
O.pass = pass;
// display
S << INF_DATA << "Password changed.\n";
}
}