User Manual
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Server APIIntroduction
Introduction123 Flash Chat Server provides some userful server APIs for the third-party application to invoke data using socket or read room or user data from server data folder. Get Server Running Status from the filesWhen a chat server is running, some parameters are stored in text files which can be read by your application. Useful information can be extracted from them. This feature is included in the standard version of 123 Flash Chat. Get numbersTo obtain a current connection number, the logon user number and the room number from a record file, use the following format: This file will real-timely change according to the chat room status. Format: <connection number >|<logon user number>|<room numbers> Get username list of each roomYou can display the user name list of each room on your webpage by retrieving data from "room_*.txt". In the <123 installation directory>/server/data/default/, you can find the following files: Send command to server to push or query the real-time dataThis feature can be very handy for an advanced user. In "<123flashchat installation directory>/server/etc/groups/default/server.xml" file you will find: The socket message string being sent is in standard syntax which will appear as shown below: Note:Remember to terminate XML-commands with a zero byte. add_roomRooms can be added on the fly using the 'add room' command.
A full sample of this command is shown below: <?xml version="1.0" encoding="UTF-8"?><Command group="default" api_pwd="3874-3459-9393-2194" type="add_room" name="test room" owner="aaa" desc="room for test" max="200" speaker="bbb" member="false" pwd="" passallmessage="true" > php sample code How to use above server APIs with php to send command to chat server, here is the sample code: <?php $host = "127.0.0.1"; $port = 51127; $apiCommand = '<?xml version="1.0" encoding="UTF-8"?><Command group="default" api_pwd="3874-3459-9393-2194" type="add_room" name="test room" owner="aaa" desc="room for test" max="200" speaker="bbb" member="false" pwd="" passallmessage="true" />'; $result = ""; $resultDoc = ""; $fp = @fsockopen($host, $port, &$errno, &$errstr, 2); if(!$fp) { echo "Failed to excute api command,maybe host chat server is not started"; } else { fputs($fp,$apiCommand."\0"); while (!feof($fp)) { $resultDoc .= fgets($fp, 1024); $resultDoc = rtrim($resultDoc); } $parser = xml_parser_create("UTF-8"); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); if (!xml_parse_into_struct($parser, $resultDoc, $values, $tags)) { printf("XML error: %s at line %d while parsing entity n", xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser)); echo "xml parse error"; } else { print_r($values); xml_parser_free($parser); fclose($fp); } } ?> For advanced details, please check webpage: del_roomRooms can be deleted dynamically using this command.
A full sample of this command can be seen below: php sample code How to use above server APIs with php to send command to chat server, here is the sample code: <?php $host = "127.0.0.1"; $port = 51127; $apiCommand = '<?xml version="1.0" encoding="UTF-8"?><Command group="default" api_pwd="3874-3459-9393-2194" type="del_room" room_id="1" />'; $result = ""; $resultDoc = ""; $fp = @fsockopen($host, $port, &$errno, &$errstr, 2); if(!$fp) { echo "Failed to excute api command,maybe host chat server is not started"; } else { fputs($fp,$apiCommand."\0"); while (!feof($fp)) { $resultDoc .= fgets($fp, 1024); $resultDoc = rtrim($resultDoc); } $parser = xml_parser_create("UTF-8"); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); if (!xml_parse_into_struct($parser, $resultDoc, $values, $tags)) { printf("XML error: %s at line %d while parsing entity n", xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser)); echo "xml parse error"; } else { print_r($values); xml_parser_free($parser); fclose($fp); } } ?> edit_roomRooms can be edited dynamically using this command. The following parameters are indispensable:
A full sample of this command is shown below: <?xml version="1.0" encoding="UTF-8"?><Command group="default" api_pwd="3874-3459-9393-2194" type="edit_room" roomid="3412" name="new name" owner="new_owner" desc="new_desc" max="300" speaker="new_speaker" member="true" pwd="new_pwd" passallmessage="false" /> php sample code How to use above server APIs with php to send command to chat server, here is the sample code: <?php $host = "127.0.0.1"; $port = 51127; $apiCommand = '<?xml version="1.0" encoding="UTF-8"?><Command group="default" api_pwd="3874-3459-9393-2194" type="edit_room" roomid="3412" name="new name" owner="new_owner" desc="new_desc" max="300" speaker="new_speaker" member="true" pwd="new_pwd" passallmessage="false" />'; $result = ""; $resultDoc = ""; $fp = @fsockopen($host, $port, &$errno, &$errstr, 2); if(!$fp) { echo "Failed to excute api command,maybe host chat server is not started"; } else { fputs($fp,$apiCommand."\0"); while (!feof($fp)) { $resultDoc .= fgets($fp, 1024); $resultDoc = rtrim($resultDoc); } $parser = xml_parser_create("UTF-8"); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); if (!xml_parse_into_struct($parser, $resultDoc, $values, $tags)) { printf("XML error: %s at line %d while parsing entity n", xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser)); echo "xml parse error"; } else { print_r($values); xml_parser_free($parser); fclose($fp); } } ?> broadcastThis command will broadcast messages to every logon user, whether or not they have entered their username or entered a room.
A full sample of this command can be seen below: <?xml version="1.0" encoding="UTF-8"?><Command group="default" api_pwd="3874-3459-9393-2194" type="broadcast" userid="test" msg="welcome to 123flashcaht" /> php sample code How to use above server APIs with php to send command to chat server, here is the sample code: <?php $host = "127.0.0.1"; $port = 51127; $apiCommand = '<?xml version="1.0" encoding="UTF-8"?><Command group="default" api_pwd="3874-3459-9393-2194" type="broadcast" userid="test" msg="welcome to 123flashcaht" />'; $result = ""; $resultDoc = ""; $fp = @fsockopen($host, $port, &$errno, &$errstr, 2); if(!$fp) { echo "Failed to excute api command,maybe host chat server is not started"; } else { fputs($fp,$apiCommand."\0"); while (!feof($fp)) { $resultDoc .= fgets($fp, 1024); $resultDoc = rtrim($resultDoc); } $parser = xml_parser_create("UTF-8"); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); if (!xml_parse_into_struct($parser, $resultDoc, $values, $tags)) { printf("XML error: %s at line %d while parsing entity n", xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser)); echo "xml parse error"; } else { print_r($values); xml_parser_free($parser); fclose($fp); } } ?> private_messageThis allows a private message to be sent to a specific user.
A full sample of this command can be seen below: <?xml version="1.0" encoding="UTF-8"?><Command group="default" api_pwd="3874-3459-9393-2194" type="private_message" dest_uid="test" msg="hello world" emotion="e2" owner_uid="admin" owner_nick="admin" b="1" i="1" u="1" color="0xff00ff" /> php sample code How to use above server APIs with php to send command to chat server, here is the sample code: <?php $host = "127.0.0.1"; $port = 51127; $apiCommand = '<?xml version="1.0" encoding="UTF-8"?><Command group="default" api_pwd="3874-3459-9393-2194" type="private_message" dest_uid="test" msg="hello world" emotion="e2" owner_uid="admin" owner_nick="admin" b="1" i="1" u="1" color="0xff00ff" />'; $result = ""; $resultDoc = ""; $fp = @fsockopen($host, $port, &$errno, &$errstr, 2); if(!$fp) { echo "Failed to excute api command,maybe host chat server is not started"; } else { fputs($fp,$apiCommand."\0"); while (!feof($fp)) { $resultDoc .= fgets($fp, 1024); $resultDoc = rtrim($resultDoc); } $parser = xml_parser_create("UTF-8"); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); if (!xml_parse_into_struct($parser, $resultDoc, $values, $tags)) { printf("XML error: %s at line %d while parsing entity n", xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser)); echo "xml parse error"; } else { print_r($values); xml_parser_free($parser); fclose($fp); } } ?> start group
A full sample of this command can be seen below: php sample code How to use above server APIs with php to send command to chat server, here is the sample code: <?php $host = "127.0.0.1"; $port = 51127; $apiCommand = '<?xml version="1.0" encoding="UTF-8"?><Command group="default" api_pwd="3874-3459-9393-2194" type="start_group"/>'; $result = ""; $resultDoc = ""; $fp = @fsockopen($host, $port, &$errno, &$errstr, 2); if(!$fp) { echo "Failed to excute api command,maybe host chat server is not started"; } else { fputs($fp,$apiCommand."\0"); while (!feof($fp)) { $resultDoc .= fgets($fp, 1024); $resultDoc = rtrim($resultDoc); } $parser = xml_parser_create("UTF-8"); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); if (!xml_parse_into_struct($parser, $resultDoc, $values, $tags)) { printf("XML error: %s at line %d while parsing entity n", xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser)); echo "xml parse error"; } else { print_r($values); xml_parser_free($parser); fclose($fp); } } ?> stop group
A full sample of this command can be seen below: php sample code How to use above server APIs with php to send command to chat server, here is the sample code: <?php $host = "127.0.0.1"; $port = 51127; $apiCommand = '<?xml version="1.0" encoding="UTF-8"?><Command group="default" api_pwd="3874-3459-9393-2194" type="stop_group"/>'; $result = ""; $resultDoc = ""; $fp = @fsockopen($host, $port, &$errno, &$errstr, 2); if(!$fp) { echo "Failed to excute api command,maybe host chat server is not started"; } else { fputs($fp,$apiCommand."\0"); while (!feof($fp)) { $resultDoc .= fgets($fp, 1024); $resultDoc = rtrim($resultDoc); } $parser = xml_parser_create("UTF-8"); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); if (!xml_parse_into_struct($parser, $resultDoc, $values, $tags)) { printf("XML error: %s at line %d while parsing entity n", xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser)); echo "xml parse error"; } else { print_r($values); xml_parser_free($parser); fclose($fp); } } ?> Related links:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||