worked more on chat

This commit is contained in:
Jonatan Pålsson 2011-02-21 15:11:28 +01:00
parent 507081c234
commit 7412087d4a
7 changed files with 25 additions and 18 deletions

View file

@ -42,11 +42,15 @@ class GGSChat:
exp = self.wTree.get_widget("entry").get_text()
nick = self.wTree.get_widget("nickBox").get_text()
if exp[0] == "/":
cmdStr = exp[1:].split(" ")
cmd = cmdStr[0]
params = ' '.join(cmdStr[1:])
self.s.send("Game-Command: %s\n" % exp[1:] +
"Token: %s\n" % self.token +
"Content-Type: text\n" +
"Content-Length: 0\n"+
"\n")
"Content-Length: %s\n" % len(params)+
"\n"+
params)
else:
exp = "<%s> %s" % (nick, exp)
self.s.send("Game-Command: chat\n"+

View file

@ -49,7 +49,7 @@ respawn_table(_Token) ->
ggs_logger:not_implemented().
%% @doc Removes a player from coordinator.
remove_player(_From, Player) ->
remove_player(_From, _Player) ->
%gen_server:cast(ggs_coordinator, {remove_player, Player}).
ggs_logger:not_implemented().
@ -66,7 +66,7 @@ handle_call({join_table, Table}, From, State) ->
{FromPlayer, _Ref} = From,
Tables = State#co_state.tables,
case lists:keyfind(Table, 1, Tables) of
{TableID, TablePID} ->
{_TableID, TablePID} ->
ggs_table:add_player(TablePID, FromPlayer),
{reply, {ok, TablePID}, State};
false ->
@ -85,8 +85,8 @@ handle_call({create_table, {force, TableID}}, From, State) ->
handle_call(_Message, _From, State) ->
{noreply, State}.
handle_cast({stop, Reason}, State) ->
{stop, normal, state};
handle_cast({stop, _Reason}, State) ->
{stop, normal, State};
%% @TODO: Implement me
%handle_cast({remove_player, Player}) ->

View file

@ -45,7 +45,7 @@ handle_call(_Message, _From, State) ->
handle_cast(_Message, State) ->
{noreply, State}.
handle_info({tcp, _Socket, RawData}, State) ->
handle_info({tcp, _Socket, _RawData}, State) ->
io:format("Got connect request!~n"),
{noreply, State};

View file

@ -6,7 +6,6 @@
%% @doc Create a new VM process. The process ID is returned and can be used
%% with for example the define method of this module.
start_link() ->
erlang_js:start(), %% @TODO: should only be done once
PortPid = spawn_link( fun() ->
process_flag(trap_exit, true),
{ok, Port} = js_driver:new(),
@ -46,5 +45,7 @@ loop(Port) ->
list_to_binary(Args)
]),
From ! {Ref, Ret},
loop(Port)
loop(Port);
{eval, JS} ->
end.

View file

@ -32,11 +32,11 @@ user_command(GameVM, Player, Command, Args) ->
loop(Table) ->
receive
{define, SourceCode} ->
{define, _SourceCode} ->
io:format("GameVM_e can't define functions, sorry!~n"),
loop(Table);
{user_command, Player, Command, Args, From, _Ref} ->
erlang:display(Player),
{user_command, Player, Command, Args, _From, _Ref} ->
erlang:display(Command),
do_stuff(Command, Args, Player, Table),
loop(Table)
end.
@ -53,6 +53,8 @@ do_stuff(Command, Args, Player, Table) ->
"lusers" ->
{ok, Players} = ggs_table:get_player_list(Table),
ggs_player:notify(Player, server,io_lib:format("~p\n",[Players]));
Other ->
"nick" ->
io:format("Changing nickname of ~p to ~p.", [Player, Args]);
_Other ->
ggs_player:notify(Player, server, "I don't know that command..\n")
end.

View file

@ -56,21 +56,21 @@ stop(_Player,_Table) ->
%% Internals
loop(#pl_state{token = Token, socket = Socket, table = Table} = State) ->
loop(#pl_state{token = _Token, socket = Socket, table = Table} = State) ->
receive
{tcp, Socket, Data} -> % Just echo for now..
io:format("Parsing via protocol module..~n"),
Parsed = ggs_protocol:parse(Data),
self() ! Parsed,
loop(State);
{notify, From, Message} ->
{notify, _From, Message} ->
gen_tcp:send(Socket, Message),
loop(State);
% Below are messages generated by the parser
{game_cmd,Cmd, Headers, Data} ->
{game_cmd,Cmd, _Headers, Data} ->
ggs_table:notify(Table, self(), {game, Cmd, Data}),
loop(State);
{srv_cmd,"define", Headers, Data} ->
{srv_cmd,"define", _Headers, Data} ->
ggs_table:notify(Table, self(), {server, define, Data}),
loop(State);
{tcp_closed, _Socket} ->

View file

@ -6,7 +6,7 @@
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3, notify_all_players/2, notify_game/3,
add_player/2, get_player_list/1]).
get_player_list/1]).
-record(state, { token, players, socket, game_vm } ).