// Получение списка пользователей указанного канала. void meth::GetChannelUsers(LogicalConnections::iterator conn, String channel_name, String &response) { if (IsUserInChannel(GetOnlineUserName(GetConnectionUser(conn)), channel_name)) { response = "[" + implode(::GetChannelUsers(channel_name)) + "]"; } else { throw(JSONError(-32001, "Virtual user is not connected to this channel. You must be in this channel to get it's members")); } }
// Отправка сообщения в общий канал. void meth::SendPublicMessage(LogicalConnections::iterator conn, String channel, String mode, String message, String &response) { String user = GetOnlineUserName(GetConnectionUser(conn)); if (IsUserInChannel(user, channel)) { /* TODO : Сделать проверку бана на пользователе */ SendChannelMessage(user, mode.ToInt(), channel, message); response = "null"; } else { throw(JSONError(-1007, "User isn't connected to this channel")); } }
void Calculated::deserializeAnswer(JSONValue const &document) { QuizQuestion::deserializeAnswer(document); if (!document["answer"].isNull()) { if (document["answer"].isNumeric()) { setAnswer(document["answer"].asDouble()); } else { throw JSONError("Expected answer to be a decimal.", document); } } }
// Регистрация пользователя. String meth::VirtualUserRegister(LogicalConnections::iterator conn, String user_nick, String user_pass, String is_female) { String response = ""; if (!GetUserOnlineStatus(conn)) { AddAuthQueue(conn, user_nick); SetAuthorizationStatus(conn, 8); UserConnect(user_nick, GetConnectionIP(conn), 1, user_pass, -1); response = "null"; } else { throw(JSONError(-1002, "You have already connected virtual user")); } return response; }
// Инициализация соединения. String meth::ConnectionInit(String app_name, SocketСonnections::iterator socket_connection, int transport) { bool persistent; SOCKET sd = socket_connection->sd; String ip = socket_connection->ip; if (ip.IsEmpty()) { throw(JSONError(-1001, "Can't determine your IP-address")); } // If this is HTTP connection then set socket handle to NULL. if (transport == 1) { sd = NULL; } // For HTTP connection !transport will return false and plugin won't try to send actions. String conn_id = AddConnection(app_name, ip, sd, !transport, transport); return "{\"conn_id\":\"" + conn_id + "\"}"; }
// Get image. void meth::GetImage(LogicalConnections::iterator conn, String image_id, String &response) { response = "\"" + LoadImage(image_id) + "\""; if (response.IsEmpty()) { throw JSONError(-1008, "Image with such id doesn't exist"); } }