worked more on chat
This commit is contained in:
parent
507081c234
commit
7412087d4a
7 changed files with 25 additions and 18 deletions
|
@ -42,11 +42,15 @@ class GGSChat:
|
||||||
exp = self.wTree.get_widget("entry").get_text()
|
exp = self.wTree.get_widget("entry").get_text()
|
||||||
nick = self.wTree.get_widget("nickBox").get_text()
|
nick = self.wTree.get_widget("nickBox").get_text()
|
||||||
if exp[0] == "/":
|
if exp[0] == "/":
|
||||||
|
cmdStr = exp[1:].split(" ")
|
||||||
|
cmd = cmdStr[0]
|
||||||
|
params = ' '.join(cmdStr[1:])
|
||||||
self.s.send("Game-Command: %s\n" % exp[1:] +
|
self.s.send("Game-Command: %s\n" % exp[1:] +
|
||||||
"Token: %s\n" % self.token +
|
"Token: %s\n" % self.token +
|
||||||
"Content-Type: text\n" +
|
"Content-Type: text\n" +
|
||||||
"Content-Length: 0\n"+
|
"Content-Length: %s\n" % len(params)+
|
||||||
"\n")
|
"\n"+
|
||||||
|
params)
|
||||||
else:
|
else:
|
||||||
exp = "<%s> %s" % (nick, exp)
|
exp = "<%s> %s" % (nick, exp)
|
||||||
self.s.send("Game-Command: chat\n"+
|
self.s.send("Game-Command: chat\n"+
|
||||||
|
|
|
@ -49,7 +49,7 @@ respawn_table(_Token) ->
|
||||||
ggs_logger:not_implemented().
|
ggs_logger:not_implemented().
|
||||||
|
|
||||||
%% @doc Removes a player from coordinator.
|
%% @doc Removes a player from coordinator.
|
||||||
remove_player(_From, Player) ->
|
remove_player(_From, _Player) ->
|
||||||
%gen_server:cast(ggs_coordinator, {remove_player, Player}).
|
%gen_server:cast(ggs_coordinator, {remove_player, Player}).
|
||||||
ggs_logger:not_implemented().
|
ggs_logger:not_implemented().
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ handle_call({join_table, Table}, From, State) ->
|
||||||
{FromPlayer, _Ref} = From,
|
{FromPlayer, _Ref} = From,
|
||||||
Tables = State#co_state.tables,
|
Tables = State#co_state.tables,
|
||||||
case lists:keyfind(Table, 1, Tables) of
|
case lists:keyfind(Table, 1, Tables) of
|
||||||
{TableID, TablePID} ->
|
{_TableID, TablePID} ->
|
||||||
ggs_table:add_player(TablePID, FromPlayer),
|
ggs_table:add_player(TablePID, FromPlayer),
|
||||||
{reply, {ok, TablePID}, State};
|
{reply, {ok, TablePID}, State};
|
||||||
false ->
|
false ->
|
||||||
|
@ -85,8 +85,8 @@ handle_call({create_table, {force, TableID}}, From, State) ->
|
||||||
handle_call(_Message, _From, State) ->
|
handle_call(_Message, _From, State) ->
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
handle_cast({stop, Reason}, State) ->
|
handle_cast({stop, _Reason}, State) ->
|
||||||
{stop, normal, state};
|
{stop, normal, State};
|
||||||
|
|
||||||
%% @TODO: Implement me
|
%% @TODO: Implement me
|
||||||
%handle_cast({remove_player, Player}) ->
|
%handle_cast({remove_player, Player}) ->
|
||||||
|
|
|
@ -45,7 +45,7 @@ handle_call(_Message, _From, State) ->
|
||||||
handle_cast(_Message, State) ->
|
handle_cast(_Message, State) ->
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
handle_info({tcp, _Socket, RawData}, State) ->
|
handle_info({tcp, _Socket, _RawData}, State) ->
|
||||||
io:format("Got connect request!~n"),
|
io:format("Got connect request!~n"),
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
%% @doc Create a new VM process. The process ID is returned and can be used
|
%% @doc Create a new VM process. The process ID is returned and can be used
|
||||||
%% with for example the define method of this module.
|
%% with for example the define method of this module.
|
||||||
start_link() ->
|
start_link() ->
|
||||||
erlang_js:start(), %% @TODO: should only be done once
|
|
||||||
PortPid = spawn_link( fun() ->
|
PortPid = spawn_link( fun() ->
|
||||||
process_flag(trap_exit, true),
|
process_flag(trap_exit, true),
|
||||||
{ok, Port} = js_driver:new(),
|
{ok, Port} = js_driver:new(),
|
||||||
|
@ -46,5 +45,7 @@ loop(Port) ->
|
||||||
list_to_binary(Args)
|
list_to_binary(Args)
|
||||||
]),
|
]),
|
||||||
From ! {Ref, Ret},
|
From ! {Ref, Ret},
|
||||||
loop(Port)
|
loop(Port);
|
||||||
|
{eval, JS} ->
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -32,11 +32,11 @@ user_command(GameVM, Player, Command, Args) ->
|
||||||
|
|
||||||
loop(Table) ->
|
loop(Table) ->
|
||||||
receive
|
receive
|
||||||
{define, SourceCode} ->
|
{define, _SourceCode} ->
|
||||||
io:format("GameVM_e can't define functions, sorry!~n"),
|
io:format("GameVM_e can't define functions, sorry!~n"),
|
||||||
loop(Table);
|
loop(Table);
|
||||||
{user_command, Player, Command, Args, From, _Ref} ->
|
{user_command, Player, Command, Args, _From, _Ref} ->
|
||||||
erlang:display(Player),
|
erlang:display(Command),
|
||||||
do_stuff(Command, Args, Player, Table),
|
do_stuff(Command, Args, Player, Table),
|
||||||
loop(Table)
|
loop(Table)
|
||||||
end.
|
end.
|
||||||
|
@ -53,6 +53,8 @@ do_stuff(Command, Args, Player, Table) ->
|
||||||
"lusers" ->
|
"lusers" ->
|
||||||
{ok, Players} = ggs_table:get_player_list(Table),
|
{ok, Players} = ggs_table:get_player_list(Table),
|
||||||
ggs_player:notify(Player, server,io_lib:format("~p\n",[Players]));
|
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")
|
ggs_player:notify(Player, server, "I don't know that command..\n")
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -56,21 +56,21 @@ stop(_Player,_Table) ->
|
||||||
|
|
||||||
%% Internals
|
%% Internals
|
||||||
|
|
||||||
loop(#pl_state{token = Token, socket = Socket, table = Table} = State) ->
|
loop(#pl_state{token = _Token, socket = Socket, table = Table} = State) ->
|
||||||
receive
|
receive
|
||||||
{tcp, Socket, Data} -> % Just echo for now..
|
{tcp, Socket, Data} -> % Just echo for now..
|
||||||
io:format("Parsing via protocol module..~n"),
|
io:format("Parsing via protocol module..~n"),
|
||||||
Parsed = ggs_protocol:parse(Data),
|
Parsed = ggs_protocol:parse(Data),
|
||||||
self() ! Parsed,
|
self() ! Parsed,
|
||||||
loop(State);
|
loop(State);
|
||||||
{notify, From, Message} ->
|
{notify, _From, Message} ->
|
||||||
gen_tcp:send(Socket, Message),
|
gen_tcp:send(Socket, Message),
|
||||||
loop(State);
|
loop(State);
|
||||||
% Below are messages generated by the parser
|
% 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}),
|
ggs_table:notify(Table, self(), {game, Cmd, Data}),
|
||||||
loop(State);
|
loop(State);
|
||||||
{srv_cmd,"define", Headers, Data} ->
|
{srv_cmd,"define", _Headers, Data} ->
|
||||||
ggs_table:notify(Table, self(), {server, define, Data}),
|
ggs_table:notify(Table, self(), {server, define, Data}),
|
||||||
loop(State);
|
loop(State);
|
||||||
{tcp_closed, _Socket} ->
|
{tcp_closed, _Socket} ->
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
%% gen_server callbacks
|
%% gen_server callbacks
|
||||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
||||||
terminate/2, code_change/3, notify_all_players/2, notify_game/3,
|
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 } ).
|
-record(state, { token, players, socket, game_vm } ).
|
||||||
|
|
||||||
|
|
Reference in a new issue