SilcClientEntry client = (SilcClientEntry)cmd->sock->user_data;
unsigned char *tmp;
unsigned int tmp_len;
- unsigned int port;
+ unsigned int port = SILC_PORT;
SILC_SERVER_COMMAND_CHECK_ARGC(SILC_COMMAND_CONNECT, cmd, 0, 0);
+ if (!client || cmd->sock->type != SILC_SOCKET_TYPE_CLIENT)
+ goto out;
+
/* Check whether client has the permissions. */
if (client->mode == SILC_UMODE_NONE) {
silc_server_command_send_status_reply(cmd, SILC_COMMAND_CLOSE,
SILC_SERVER_COMMAND_CHECK_ARGC(SILC_COMMAND_CLOSE, cmd, 0, 0);
+ if (!client || cmd->sock->type != SILC_SOCKET_TYPE_CLIENT)
+ goto out;
+
/* Check whether client has the permissions. */
if (client->mode == SILC_UMODE_NONE) {
silc_server_command_send_status_reply(cmd, SILC_COMMAND_CLOSE,
SILC_SERVER_COMMAND_CHECK_ARGC(SILC_COMMAND_SHUTDOWN, cmd, 0, 0);
+ if (!client || cmd->sock->type != SILC_SOCKET_TYPE_CLIENT)
+ goto out;
+
/* Check whether client has the permission. */
if (client->mode == SILC_UMODE_NONE) {
silc_server_command_send_status_reply(cmd, SILC_COMMAND_SHUTDOWN,
SILC_CF_LAG | SILC_CF_REG | SILC_CF_OPER, 2),
SILC_CLIENT_CMD(info, INFO, "INFO", SILC_CF_LAG | SILC_CF_REG, 2),
SILC_CLIENT_CMD(connect, CONNECT, "CONNECT",
- SILC_CF_LAG | SILC_CF_REG | SILC_CF_OPER, 2),
+ SILC_CF_LAG | SILC_CF_REG | SILC_CF_OPER, 3),
SILC_CLIENT_CMD(ping, PING, "PING", SILC_CF_LAG | SILC_CF_REG, 2),
SILC_CLIENT_CMD(oper, OPER, "OPER",
SILC_CF_LAG | SILC_CF_REG | SILC_CF_OPER, 2),
SILC_CLIENT_CMD(close, CLOSE, "CLOSE",
SILC_CF_LAG | SILC_CF_REG | SILC_CF_OPER, 2),
SILC_CLIENT_CMD(shutdown, SHUTDOWN, "SHUTDOWN",
- SILC_CF_LAG | SILC_CF_REG | SILC_CF_OPER, 2),
+ SILC_CF_LAG | SILC_CF_REG | SILC_CF_OPER, 1),
SILC_CLIENT_CMD(silcoper, SILCOPER, "SILOPER",
SILC_CF_LAG | SILC_CF_REG | SILC_CF_SILC_OPER, 2),
SILC_CLIENT_CMD(leave, LEAVE, "LEAVE", SILC_CF_LAG | SILC_CF_REG, 2),
silc_client_command_free(cmd);
}
-SILC_CLIENT_CMD_FUNC(connect)
-{
-}
-
/* Command PING. Sends ping to server. This is used to test the
communication channel. */
silc_client_command_free(cmd);
}
-SILC_CLIENT_CMD_FUNC(oper)
-{
-}
-
SILC_CLIENT_CMD_FUNC(trace)
{
}
silc_client_command_free(cmd);
}
+SILC_CLIENT_CMD_FUNC(silcoper)
+{
+}
+
+SILC_CLIENT_CMD_FUNC(oper)
+{
+}
+
+/* CONNECT command. Connects the server to another server. */
+
+SILC_CLIENT_CMD_FUNC(connect)
+{
+ SilcClientCommandContext cmd = (SilcClientCommandContext)context;
+ SilcClientConnection conn = cmd->conn;
+ SilcBuffer buffer;
+ unsigned char port[4];
+
+ if (!cmd->conn) {
+ SILC_NOT_CONNECTED(cmd->client, cmd->conn);
+ COMMAND_ERROR;
+ goto out;
+ }
+
+ if (cmd->argc < 2) {
+ cmd->client->ops->say(cmd->client, conn,
+ "Usage: /CONNECT <server> [<port>]");
+ COMMAND_ERROR;
+ goto out;
+ }
+
+ if (cmd->argc == 3)
+ SILC_PUT32_MSB(atoi(cmd->argv[2]), port);
+
+ if (cmd->argc == 3)
+ buffer = silc_command_payload_encode_va(SILC_COMMAND_CONNECT, 0, 2,
+ 1, cmd->argv[1],
+ strlen(cmd->argv[1]),
+ 2, port, 4);
+ else
+ buffer = silc_command_payload_encode_va(SILC_COMMAND_CONNECT, 0, 1,
+ 1, cmd->argv[1],
+ strlen(cmd->argv[1]));
+ silc_client_packet_send(cmd->client, conn->sock, SILC_PACKET_COMMAND, NULL,
+ 0, NULL, NULL, buffer->data, buffer->len, TRUE);
+ silc_buffer_free(buffer);
+
+ /* Notify application */
+ COMMAND;
+
+ out:
+ silc_client_command_free(cmd);
+}
+
SILC_CLIENT_CMD_FUNC(restart)
{
}
{
}
+/* SHUTDOWN command. Shutdowns the server. */
+
SILC_CLIENT_CMD_FUNC(shutdown)
{
+ SilcClientCommandContext cmd = (SilcClientCommandContext)context;
+
+ if (!cmd->conn) {
+ SILC_NOT_CONNECTED(cmd->client, cmd->conn);
+ COMMAND_ERROR;
+ goto out;
+ }
+
+ /* Send the command */
+ silc_client_send_command(cmd->client, cmd->conn,
+ SILC_COMMAND_SHUTDOWN, 0, 0);
+
+ /* Notify application */
+ COMMAND;
+
+ out:
+ silc_client_command_free(cmd);
}
-SILC_CLIENT_CMD_FUNC(silcoper)
-{
-}
-
/* LEAVE command. Leaves a channel. Client removes itself from a channel. */
SILC_CLIENT_CMD_FUNC(leave)
SILC_CLIENT_CMD_REPLY(list, LIST),
SILC_CLIENT_CMD_REPLY(topic, TOPIC),
SILC_CLIENT_CMD_REPLY(invite, INVITE),
- SILC_CLIENT_CMD_REPLY(quit, QUIT),
SILC_CLIENT_CMD_REPLY(kill, KILL),
SILC_CLIENT_CMD_REPLY(info, INFO),
SILC_CLIENT_CMD_REPLY(connect, CONNECT),
SILC_CLIENT_CMD_REPLY(kick, KICK),
SILC_CLIENT_CMD_REPLY(restart, RESTART),
SILC_CLIENT_CMD_REPLY(close, CLOSE),
- SILC_CLIENT_CMD_REPLY(die, DIE),
+ SILC_CLIENT_CMD_REPLY(shutdown, SHUTDOWN),
SILC_CLIENT_CMD_REPLY(silcoper, SILCOPER),
SILC_CLIENT_CMD_REPLY(leave, LEAVE),
SILC_CLIENT_CMD_REPLY(users, USERS),
silc_client_command_reply_free(cmd);
}
-SILC_CLIENT_CMD_REPLY_FUNC(quit)
-{
-}
-
SILC_CLIENT_CMD_REPLY_FUNC(kill)
{
}
silc_client_command_reply_free(cmd);
}
-SILC_CLIENT_CMD_REPLY_FUNC(connect)
-{
-}
-
/* Received reply to PING command. The reply time is shown to user. */
SILC_CLIENT_CMD_REPLY_FUNC(ping)
silc_client_command_reply_free(cmd);
}
-SILC_CLIENT_CMD_REPLY_FUNC(oper)
-{
-}
-
/* Received reply for JOIN command. */
SILC_CLIENT_CMD_REPLY_FUNC(join)
silc_client_command_reply_free(cmd);
}
+SILC_CLIENT_CMD_REPLY_FUNC(silcoper)
+{
+}
+
+SILC_CLIENT_CMD_REPLY_FUNC(oper)
+{
+}
+
+SILC_CLIENT_CMD_REPLY_FUNC(connect)
+{
+}
+
SILC_CLIENT_CMD_REPLY_FUNC(restart)
{
}
{
}
-SILC_CLIENT_CMD_REPLY_FUNC(die)
+SILC_CLIENT_CMD_REPLY_FUNC(shutdown)
{
}
-SILC_CLIENT_CMD_REPLY_FUNC(silcoper)
-{
-}
-
/* Reply to LEAVE command. */
SILC_CLIENT_CMD_REPLY_FUNC(leave)