#!/php -q <?php /* Run from command line: > php -q server.php */ require_once "includes/global.inc"; /* * Standard host and port settings * Keep in mind that on a live host, you'll want to bind to the outbound IP or host name, not localhost or 127.0.0.1, etc. */ define("HOST", "127.0.0.1"); define("PORT", "12345"); /* * The following defines are for the WebSocket Handshake, and should be set according to your server. * If you're testing locally (based on the HOST and PORT above), yours should look like the values below. * * If you're deploying the application on a live server, the values would like more like: * RESOURCE: /server/game.php (as in example.com/server/game.php) * HOST: example.com:12345 * ORIGIN: example.com * * If you're not using WebSocket, this doesn't matter at all */ define("WS_RESOURCE", "/phudbase/server/game.php"); define("WS_HOST", "127.0.0.1:12345"); define("WS_ORIGIN", "http://127.0.0.1"); // Establish the game server // $server = new GameServer(HOST, PORT, GC_WEBSOCKET, 256); $server->create(); $server->set_client_class("GameClient"); // If you're using flash, you'll want to set up a Policy server here, too (and have it process in the game loop below) // // Create game instance // $game = new Game(); // Very basic sample of grid based room structure // $rooms = array(); $rooms[-1] = array(); $rooms[0] = array(); $rooms[1] = array(); $rooms[-1][1] = new Room(1, "Northwest Corner", "The northwest corner is awfully pretty.", -1, 1); $rooms[-1][0] = new Room(2, "Western Wall", "The western wall is awfully pretty.", -1, 0); $rooms[-1][-1] = new Room(3, "Southwest Corner", "The southwest corner is awfully pretty.", -1, -1); $rooms[0][1] = new Room(4, "Northern Wall", "The northern wall is awfully pretty.", 0, 1); $rooms[0][0] = new Room(5, "The Shire", "All around you sprawls the fantastic greenery and quaint homes of hobbit-folk. Sounds of merriment float on the breeze with the smells of tobacco and cooking and, wait... Ah, balls, it's just the starting area of Phud.", 0, 0); $rooms[0][-1] = new Room(6, "Southern Wall", "The southern wall is awfully pretty.", 0, -1); $rooms[1][1] = new Room(7, "Northeast Corner", "The northeast corner is awfully pretty.", 1, 1); $rooms[1][0] = new Room(8, "Eastern Wall", "The eastern wall is awfully pretty.", 1, 0); $rooms[1][-1] = new Room(9, "Southeast Corner", "The southeast corner is awfully pretty.", 1, -1); // Let's set up a few NPCs for fun // $c = new Character(count($game->getCharacters())+1, "Bob the Builder", "Bob likes to build things and is very, very positively oriented.", GO_TYPE_NPC); $c = new Character(count($game->getCharacters())+1, "Phudder the Dairy Farmer", "You don't want to know the things Phudder knows about cows....", GO_TYPE_NPC); $c = new Character(count($game->getCharacters())+1, "JFitz the Creator Dude", "An all around awesome guy, JFitz built this place over a period of several years, then stripped it clean in a night.", GO_TYPE_NPC); $c = new Character(count($game->getCharacters())+1, "Sabs the Creator Dude's Wife", "Sabs is the reason JFitz has gotten so good at programming. You decide why.", GO_TYPE_NPC); unset($c); while ($game->isRunning()) { // Process reads/writes over the game server // $server->process(); // Process game actions // $game->ExecuteLoop(); // Take a breather // usleep(25000); } ?>