Skip to content

Commit

Permalink
Adapted server to Yaws 1.94. Added script for automatic Yaws startup.…
Browse files Browse the repository at this point in the history
… Updated readme with markdown.
  • Loading branch information
margnus1 committed Oct 21, 2012
1 parent 84723b2 commit 5f88b11
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 161 deletions.
4 changes: 4 additions & 0 deletions Makefile
Expand Up @@ -42,6 +42,10 @@ start_client: all
start_server: all
erl -name kidserver -setcookie kid-mud -pa ebin -mnesia dir database -eval "application:start(mnesia)" -eval "application:start(kidmud)"

start_webserver: all
mkdir -p yaws/logs yaws/include
cd yaws; ./start_here.sh

setup: all
mkdir database
erl -name kidserver -noshell -pa ebin -mnesia dir database -s database setup -s erlang halt
Expand Down
95 changes: 0 additions & 95 deletions README.txt

This file was deleted.

82 changes: 82 additions & 0 deletions Readme.md
@@ -0,0 +1,82 @@
Kid-MUD
=======

_KID is dirty_
_Because he is playing in the MUD_


Project Description
-------------------
A MUD (Multi User Dungeon) is a text- based online game where players
perform actions by typing them (such as “go north” or “attack goblin”).
The world is partitioned into zones, and each player exists in one zone
at any one time, and can move to neighboring zones. Zones can be occupied
by several players as well as one or more NPC (Non player characters) that
can be interacted with (e.g. attacked).

Kid-MUD is a Erlang MUD with scalability as a focus. It is currently early in
development.


Who are we?
-----------

Eric Arnerlöv <eric.arnerlov.4839@student.uu.se>
Michael Bergroth <michael.bergroth.5739@student.uu.se>
Magnus Lång <magnus.lang.7837@student.uu.se>
Mikael Wiberg <mikael.wiberg.6269@studnet.uu.se>


May the source be with you
--------------------------

Everything you need to compile and run the system is included in this
directory.

However, you might want to get the most up to date version of this
directory.

To fetch the source code for this project type the following command:

FIRST TIME
$ git clone git://github.com/margnus1/kid-mud.git

AFTERWARS
$ git pull

Dependencies
------------
This software was developed and tested using Erlang R15B01 and Yaws 1.94

Make it happen
--------------
Using the make utility you can perform the following actions:

make ==> Compiles the Erlang source files if necessary.
make archive ==> Creates a gziped tar archive of this directory.
make clean ==> Removes all beam files and html files generated by Edoc.
make doc ==> Generates Edoc documentation in the doc/html directory.
make setup ==> Performs first-time setup of database
make start_server ==> Starts the server.
make start_webserver ==> Starts the WebSocket based Yaws interface.
make start_client ==> Starts the client.
make test ==> Runs all Eunit tests.


To run and test the server
--------------------------

To use the MUD, you need to start the server. The server needs a database, so
begin by typing "make setup". This is nessescary only once.
You can then use either the terminal or websocket interfaces
* If you want to use the terminal interface, you start the server by typing "make start_server".
To connect to it from another terminal, type "make start_client" and use the supplied command to start a client sesion against the server.
* If you want to use the WebSocket interface, you start the server by typing "make start_webserver".
You can then connect to it on adress "http://localhost:8080"

When you have logged in, you can write this, among other things:
go north ==> Moves to zone adjacent to the north
say Hi! ==> Says Hi! to the other players
attack Peter ==> Attacks Peter
stop ==> You just wanted to intimidate him, so you stop attacking
logout ==> Peter is mad with you, so you better leave
124 changes: 62 additions & 62 deletions include/yaws_api.hrl
Expand Up @@ -8,34 +8,34 @@
-author('klacke@hyber.org').

-record(arg, {
clisock, %% the socket leading to the peer client
client_ip_port, %% {ClientIp, ClientPort} tuple
headers, %% headers
req, %% request
clidata, %% The client data (as a binary in POST requests)
server_path, %% The normalized server path
%% (pre-querystring part of URI)
querydata, %% For URIs of the form ...?querydata
%% equiv of cgi QUERY_STRING
appmoddata, %% (deprecated - use pathinfo instead) the remainder
%% of the path leading up to the query
docroot, %% Physical base location of data for this request
docroot_mount, %% virtual directory e.g /myapp/ that the docroot
%% refers to.
fullpath, %% full deep path to yaws file
cont, %% Continuation for chunked multipart uploads
state, %% State for use by users of the out/1 callback
pid, %% pid of the yaws worker process
opaque, %% useful to pass static data
appmod_prepath, %% (deprecated - use prepath instead) path in front
%%of: <appmod><appmoddata>
prepath, %% Path prior to 'dynamic' segment of URI.
%% ie http://some.host/<prepath>/<script-point>/d/e
%% where <script-point> is an appmod mount point,
%% or .yaws,.php,.cgi,.fcgi etc script file.
pathinfo %% Set to '/d/e' when calling c.yaws for the request
%% http://some.host/a/b/c.yaws/d/e
%% equiv of cgi PATH_INFO
clisock, % the socket leading to the peer client
client_ip_port, % {ClientIp, ClientPort} tuple
headers, % headers
req, % request
clidata, % The client data (as a binary in POST requests)
server_path, % The normalized server path
% (pre-querystring part of URI)
querydata, % For URIs of the form ...?querydata
% equiv of cgi QUERY_STRING
appmoddata, % (deprecated - use pathinfo instead) the remainder
% of the path leading up to the query
docroot, % Physical base location of data for this request
docroot_mount, % virtual directory e.g /myapp/ that the docroot
% refers to.
fullpath, % full deep path to yaws file
cont, % Continuation for chunked multipart uploads
state, % State for use by users of the out/1 callback
pid, % pid of the yaws worker process
opaque, % useful to pass static data
appmod_prepath, % (deprecated - use prepath instead) path in front
% of: <appmod><appmoddata>
prepath, % Path prior to 'dynamic' segment of URI.
% ie http://some.host/<prepath>/<script-point>/d/e
% where <script-point> is an appmod mount point,
% or .yaws,.php,.cgi,.fcgi etc script file.
pathinfo % Set to '/d/e' when calling c.yaws for the request
% http://some.host/a/b/c.yaws/d/e
% equiv of cgi PATH_INFO
}).


Expand Down Expand Up @@ -73,16 +73,16 @@
authorization,
transfer_encoding,
x_forwarded_for,
other = [] %% misc other headers
other = [] % misc other headers
}).




-record(url,
{scheme, %% undefined means not set
host, %% undefined means not set
port, %% undefined means not set
{scheme, % undefined means not set
host, % undefined means not set
port, % undefined means not set
path = [],
querypart = []}).

Expand All @@ -104,41 +104,41 @@


-record(redir_self, {
host, %% string() - our own host
scheme, %% http | https
scheme_str, %% "https://" | "http://"
port, %% integer() - our own port
port_str %% "" | ":<int>" - the optional port part
%% to append to the url
host, % string() - our own host
scheme, % http | https
scheme_str, % "https://" | "http://"
port, % integer() - our own port
port_str % "" | ":<int>" - the optional port part
% to append to the url
}).

%% Corresponds to the frame sections as in
%% http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-08#section-4
%% plus 'data' and 'ws_state'
-record(ws_frame_info, {
fin,
rsv,
opcode,
masked,
masking_key,
length,
payload,
data, %% The unmasked payload. Makes payload redundant.
ws_state %% The ws_state after unframing this frame.
%% This is useful for the endpoint to know what type of
%% fragment a potentially fragmented message is.
}).

%----------------------------------------------------------------------
% The state of a WebSocket connection.
% This is held by the ws owner process and passed in calls to yaws_api.
%----------------------------------------------------------------------
fin,
rsv,
opcode,
masked,
masking_key,
length,
payload,
data, % The unmasked payload. Makes payload redundant.
ws_state % The ws_state after unframing this frame.
% This is useful for the endpoint to know what type of
% fragment a potentially fragmented message is.
}).

%%----------------------------------------------------------------------
%% The state of a WebSocket connection.
%% This is held by the ws owner process and passed in calls to yaws_api.
%%----------------------------------------------------------------------
-type frag_type() :: text
| binary
| none. %% The WebSocket is not expecting continuation
%% of any fragmented message.
| binary
| none. % The WebSocket is not expecting continuation
% of any fragmented message.
-record(ws_state, {
vsn :: integer(), % WebSocket version number
sock, % gen_tcp or gen_ssl socket
frag_type :: frag_type()
}).
vsn :: integer(), % WebSocket version number
sock, % gen_tcp or gen_ssl socket
frag_type :: frag_type()
}).
19 changes: 17 additions & 2 deletions src/kidmud.erl
@@ -1,4 +1,4 @@
%% Copyright (c) 2012 Magnus Lång, Mikael Wiberg and Michael Bergroth, Eric Arn\erlöv
%% Copyright (c) 2012 Magnus Lång, Mikael Wiberg and Michael Bergroth, Eric Arnerlöv
%% See the file license.txt for copying permission.

%%%-------------------------------------------------------------------
Expand All @@ -13,7 +13,7 @@
-behaviour(application).

%% Application callbacks
-export([start/2, stop/1]).
-export([start/0, start/2, stop/1]).

%%%===================================================================
%%% Application callbacks
Expand Down Expand Up @@ -45,6 +45,21 @@ start(_StartType, _StartArgs) ->
Error
end.

%%--------------------------------------------------------------------
%% @doc
%% This function is used for starting Kid-MUD in a yaws instance with
%% the runmod argument. It will wait until mnesia starts and then
%% start Kid-MUD.
%% @end
%%--------------------------------------------------------------------
start() ->
case application:start(kidmud) of
{error,{not_started,mnesia}} ->
timer:apply_after(50, kidmud, start, []),
{warning, "Waiting for mnesia to start..."};
Answer -> Answer
end.

%%--------------------------------------------------------------------
%% @private
%% @doc
Expand Down
4 changes: 2 additions & 2 deletions src/ws_client.erl
Expand Up @@ -138,8 +138,8 @@ handle_message(#ws_frame_info{opcode=close,
handle_message(#ws_frame_info{}, Acc) ->
{noreply, Acc}.

input({text, Name}, initial, Socket) ->
Relay = spawn(?MODULE, relay, [Socket]),
input({text, Name}, initial, _Socket) ->
Relay = spawn(?MODULE, relay, [self()]),
AsciiName = unicode:characters_to_list(Name),
case check_name(AsciiName) of
ok ->
Expand Down

0 comments on commit 5f88b11

Please sign in to comment.