aboutsummaryrefslogtreecommitdiffstats
path: root/inc/messages.inc
diff options
context:
space:
mode:
authorpiernov <piernov@piernov.org>2016-05-08 20:14:40 +0200
committerpiernov <piernov@piernov.org>2016-05-08 20:14:40 +0200
commitfaefddcb8b3d3ac491331b702f8a8ac6fe58a894 (patch)
tree106ee88e861eae0fc9c783243db3668e8c9c8ae1 /inc/messages.inc
parentf1677164c3f46785f6d9380b68cdeba58a680404 (diff)
downloadcandybox-faefddcb8b3d3ac491331b702f8a8ac6fe58a894.tar.gz
candybox-faefddcb8b3d3ac491331b702f8a8ac6fe58a894.tar.bz2
candybox-faefddcb8b3d3ac491331b702f8a8ac6fe58a894.tar.xz
candybox-faefddcb8b3d3ac491331b702f8a8ac6fe58a894.zip
First PHPDoc push, Inventory not complete
Diffstat (limited to 'inc/messages.inc')
-rw-r--r--inc/messages.inc33
1 files changed, 33 insertions, 0 deletions
diff --git a/inc/messages.inc b/inc/messages.inc
index 3a7d9b1..50bbafb 100644
--- a/inc/messages.inc
+++ b/inc/messages.inc
@@ -1,5 +1,14 @@
<?php
+/**
+ * Server to client error/info messages list and helpers.
+ *
+ * @author Alexandre Renoux
+ * @author Pierre-Emmanuel Novac
+ */
+/**
+ * Messages list.
+ */
$messages = array(
"shop_already_built" => "You have already built a shop.",
"gold_insufficient" => "You don't have enough gold.",
@@ -18,6 +27,14 @@ $messages = array(
"upload_success" => "Save file uploaded successfully: %s",
);
+/**
+ * Sends a message to the client.
+ *
+ * @param string $type message type, for example "info" or "error"
+ * @param string $msg message content
+ * @param string $fmt optional parameters to apply when formating message string
+ * @return void
+ */
function sendMessage($type, $msg, $fmt = null) {
global $messages;
$text = $messages[$msg];
@@ -25,10 +42,26 @@ function sendMessage($type, $msg, $fmt = null) {
echo json_encode(array($type => $text));
}
+/**
+ * Sends an error message to the client.
+ * Simple wrapper calling sendMessage with "error" as $type.
+ *
+ * @param string $msg message content
+ * @param string $fmt optional parameters to apply when formating message string
+ * @return void
+ */
function sendError($msg, $fmt = null) {
sendMessage("error", $msg, $fmt);
}
+/**
+ * Sends an info message to the client.
+ * Simple wrapper calling sendMessage with "info" as $type.
+ *
+ * @param string $msg message content
+ * @param string $fmt optional parameters to apply when formating message string
+ * @return void
+ */
function sendInfo($msg, $fmt = null) {
sendMessage("info", $msg, $fmt);
}