Skip to content

Commit

Permalink
add new code
Browse files Browse the repository at this point in the history
  • Loading branch information
HpyHacking committed Apr 27, 2012
1 parent 83a0ce9 commit def1504
Show file tree
Hide file tree
Showing 22 changed files with 1,514 additions and 1,308 deletions.
4 changes: 3 additions & 1 deletion chapter_1/demo.erl
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
-module(demo).
-export([double/1, area/1]).

double(Value) -> times(Value, 2).
double(Value) ->
times(Value, 2).

times(X, Y) -> X * Y.

area(sharp) -> {sharp, 1};
Expand Down
4 changes: 2 additions & 2 deletions chapter_12/gensrv.erl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-module(sample_gensrv).
-module(gensrv).
-export([start/0, stop/0]).
-export([init/1, handle_cast/2, handle_call/3, terminate/2]).
-export([say_hello/1]).
Expand All @@ -7,7 +7,7 @@

start() ->
Name = "Jack",
gen_server:start({local, ?MODULE}, ?MODULE, Name, []).
gen_server:start({global, {test, ?MODULE}}, ?MODULE, Name, []).

init(Name) ->
io:format("Init OPT ~p~n", [Name]),
Expand Down
9 changes: 0 additions & 9 deletions chapter_12/usr-1.0/ebin/usr.app

This file was deleted.

16 changes: 16 additions & 0 deletions chapter_15/tcp_server.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-module(tcp_server).
-export([start/0, send/2]).

-define(log(Message),
fun() ->
io:foramt("<~p> LOGGER: ~p~n", [self(), Message])
end()).

start() ->
{ok, ListenSocket} = gen_tcp:listen(5000, [binary, {active, false}]),
wait_connect(ListenSocket, 0).

wait_connect(ListenSocket, Count) ->
?log("Begin Wait Connection ...").
{ok, Socket} = gen_tcp:accept(ListenSocket),
?log("Receive a TCP request ...").
44 changes: 44 additions & 0 deletions chapter_15/udp_server.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
-module(udp_server).
-export([start_link/0, stop/0]).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2]).
-export([send/1]).

-behaviour(gen_server).

-define(SERVER_PORT, 18000).
-define(CLIENT_PORT, 18001).

start_link() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, null, []).

stop() ->
gen_server:cast(?MODULE, stop).

init(_Params) ->
{ok, Sock} = gen_udp:open(?SERVER_PORT),
io:format("Init Sock ~p~n", [Sock]),
{ok, {server, Sock}}.

terminate(Reason, {server, Sock}) ->
gen_udp:close(Sock).

handle_cast(stop, {server, Sock}) ->
{stop, normal, {server, Sock}}.

handle_info({udp, Client, _Ip, _Port, Msg}, LoopData) ->
io:format("receive udp data ~p from ~p~n", [Msg, Client]),
{noreply, LoopData};

handle_info(Msg, LoopData) ->
io:format("receive info ~p~n", [Msg]),
{noreply, LoopData}.

send(Msg) ->
gen_server:call(?MODULE, {message, Msg}).

handle_call({message, Msg}, _From, {server, Sock}) ->
{ok, Client} = gen_udp:open(?CLIENT_PORT),
io:format("Sock ~p Client ~p~n", [Sock, Client]),
gen_udp:send(Client, {127,0,0,1}, ?SERVER_PORT, Msg),
gen_udp:close(Client),
{reply, ok, {server, Sock}}.
1 change: 0 additions & 1 deletion chapter_2/example.erl
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ even(Int) when Int rem 2 == 1 -> false.
number(Num) when is_integer(Num) -> interger;
number(Num) when is_float(Num) -> float;
number(_Other) -> false.

16 changes: 16 additions & 0 deletions dbg/ping.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-module(ping).
-export([start/0, send/1, loop/0]).

start() -> spawn_link(ping, loop, []).

send(Pid) ->
Pid ! {self(), ping},
receive pong -> pong end.

loop() ->
receive
{Pid, ping} ->
spawn(crash, do_not_exist, []),
Pid ! pong,
loop()
end.
37 changes: 37 additions & 0 deletions gen_fsm/code_lock.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
-module(code_lock).
-behaviour(gen_fsm).

-export([start_link/1]).
-export([button/1]).
-export([init/1, locked/2, open/2]).

% client function
%
start_link(Code) ->
gen_fsm:start({local, ?MODULE}, code_lock, Code, []).

button(Digit) ->
gen_fsm:send_event(?MODULE, {button, Digit}).

% callback function
%
init(Code) ->
io:format("new code lock ~p ~n", [Code]),
{ok, locked, {[], Code}}.

locked({button, Digit}, {SoFar, Code}) ->
case [Digit|SoFar] of
Code ->
% do_unlock(),
io:format("do unlock"),
{next_state, open, {[], Code}, 3000};
Incomplete when length(Incomplete)<length(Code) ->
{next_state, locked, {Incomplete, Code}};
_Wrong ->
{next_state, locked, {[], Code}}
end.

open(timeout, State) ->
io:format("do lock"),
% do_lock(),
{next_state, locked, State}.
24 changes: 24 additions & 0 deletions gen_fsm/door.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-module(door).
-export([start/1, init/1]).

start(Codes) ->
spawn(fun() -> door:init(Codes) end).

init(Codes) ->
init_lock(Codes),
loop().

init_lock([]) ->
ok;

init_lock([Code|Codes]) ->
Res = code_lock:start_link(Code),
io:format("Result is ~p~n", [Res]),
init_lock(Codes).

loop() ->
receive
ok ->
{ok},
loop()
end.
39 changes: 39 additions & 0 deletions openpoker-server/README
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,45 @@ OpenPoker is released under a dual GPL/commercial license.

Please see doc/install.txt for installation instructions and visit http://groups.google.com/group/openpoker if you have questions.

src/betting 赌注状态机(cardgame)
src/bits
src/blinds 盲注状态机(cardgame)
src/bot 机器人
src/cardgame 纸牌游戏状态机宿主(gen_fsm)
src/common.hrl 公共Header定义(header)
src/counter 累加器(lib)
src/db 数据库相关(gen_server)
src/deal_cards 发牌状态机(cardgame)
src/deck 扑克牌(gen_server)
src/delayed_start 延迟游戏启动状态机(cardgame)
src/fixed_limit
src/game
src/gateway
src/hand 手牌(gen_server)
src/id
src/ircdb 聊天室
src/ircdb.hrl 聊天室定义
src/lang 语言文字定义(lib)
src/lang.hrl
src/login 登陆(lib)
src/monitor
src/multibot
src/observer
src/player 玩家(gen_server)
src/pot
src/proto 协议(lib)
src/proto.hrl 协议定义(header)
src/schema 数据库结构(lib)
src/schema.hrl 结构定义(header)
src/server 游戏服务器(gen_server)
src/showdown 游戏结束状态机(cardgame)
src/tcp_server 网络通信服务器(gen_server)
src/test
src/test
src/texas 德州扑克
src/util
src/visitor 访问者(gen_server)

More information can also be found at http://wagerlabs.com.

Thanks, Joel Reymont
Loading

0 comments on commit def1504

Please sign in to comment.