This repository has been archived on 2025-08-18. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
GGS/games/JS-chat/chat_server.js
2011-05-03 18:34:19 +02:00

23 lines
708 B
JavaScript

function playerCommand(player_id, command, args) {
if(command == "/nick") {
changeNick(player_id, args);
} else if(command == "message") {
message(player_id, args);
}
}
function changeNick(player_id, nick) {
var old_nick = GGS.localStorage.getItem("nick_" + player_id);
GGS.localStorage.setItem("nick_" + player_id, nick);
if (!old_nick) {
GGS.sendCommandToAll("notice", nick + " joined");
} else {
GGS.sendCommandToAll("notice", old_nick + " is now called " + nick);
}
}
function message(player_id, message) {
var nick = GGS.localStorage.getItem("nick_" + player_id);
GGS.sendCommandToAll('message', nick + "> " + message);
}