Roman Dayneko 11 лет назад
Родитель
Сommit
382f6eabc5

+ 58 - 44
apps/db/include/accounts.hrl

@@ -6,10 +6,13 @@
 %% @end
 %%--------------------------------------------------------------------
 
--ifndef(NSM_ACCOUNTS).
--define(NSM_ACCOUNTS, true).
+-ifndef(ACCOUNTS_HRL).
+-define(ACCOUNTS_HRL, "accounts_hrl").
+
+-include_lib("kvs/include/kvs.hrl").
 
 -type currency()         :: kakaush | quota | game_point | money.
+
 %% game events when points affected
 -type game_event_type()  :: round_start | round_end | game_start | game_end | tour_start.
 -type tournament_type()  :: standalone | elimination | pointing | lucky. %% FIXME: Copypasted from game_okey.hrl
@@ -23,80 +26,91 @@
 
 %% common fields for all accounts
 
--record(account, {id          :: account_id(),
-				  debet       :: integer(),
-				  credit      :: integer(),
-				  last_change :: integer() %% can be negative. Store last change
-				                           %% to resolve conflicts just by applying
-                                           %% all changes to one of the conflicting
-
-				  }).
+-record(account, {
+          ?ITERATOR(feed),
+          account_id          :: account_id(),
+          debet       :: integer(),
+          credit      :: integer(),
+          
+          %% can be negative. Store last change
+          %% to resolve conflicts just by applying
+          %% all changes to one of the conflicting
+          last_change :: integer()
+         }).
 
 -define(ACC_ID(Account, Currency), {Account, Currency}). %% account id helper
 
 -record(pointing_rule,
 		{
-		 id,            %% {Game, GameType, Rounds} | {Game, GameType}
-		 game,
-		 game_type,
-		 rounds,        %% rounds | points | undefined
-		 kakush_winner, %% kakush points will be assigned for the winner of the game.
-		 kakush_other,  %% kakush points will be assigned for the rest of the
- 		                %% players other then winner, per player.
-		 quota,         %% quota, no of quota will be charged to players.
-		 game_points    %% game points will be assigned at the end of the game
-		                %% to winner player
-		}).
+          ?ITERATOR(feed),
+          pointing_rule_id,            %% {Game, GameType, Rounds} | {Game, GameType}
+          game,
+          game_type,
+          rounds,        %% rounds | points | undefined
+          kakush_winner, %% kakush points will be assigned for the winner of the game.
+          kakush_other,  %% kakush points will be assigned for the rest of the
+          
+          %% players other then winner, per player.
+          %% quota, no of quota will be charged to players.
+          quota,
+
+          %% game points will be assigned at the end of the game
+          %% to winner player
+          game_points    
+		}
+       ).
 
 %% Transaction info definitions. This records should be used as
 %% values in #transaction.info. 'ti' prefix = 'transaction info'.
 
 -record(ti_game_event,
         {
-         id                           :: integer(),         %% GameId
-         type                         :: game_event_type(),
-         game_name                    :: game_name(),
-         game_mode                    :: game_mode(),
-         double_points                :: integer(),
-         tournament_type = standalone :: tournament_type()
-        }).
+          id                           :: integer(),         %% GameId
+          type                         :: game_event_type(),
+          game_name                    :: game_name(),
+          game_mode                    :: game_mode(),
+          double_points                :: integer(),
+          tournament_type = standalone :: tournament_type()
+        }
+       ).
 
 -record(ti_payment,
 		{
-		 id                         :: integer()
+          id                         :: integer()
 		}).
 
 -record(ti_admin_change,
 		{
-		 reason                     :: binary()
-		 }).
+          reason                     :: binary()
+        }
+       ).
 
 -record(ti_default_assignment,
 		{
 
-		 }).
+        }).
 
--type transaction_info() :: #ti_game_event{} | #ti_payment{} | #ti_admin_change{}|#ti_default_assignment{}.
+-type transaction_info() :: #ti_game_event{} | #ti_payment{} | #ti_admin_change{} | #ti_default_assignment{}.
 
 -record(user_transaction, {user,top}).
 
 -record(transaction,
 		{
-		 id                         :: transaction_id(),
-		 commit_time                :: erlang:now(),
-		 amount                     :: integer(),    %% amount to move between accounts
-		 remitter                   :: account_id(), %% accout that gives money/points
-		 acceptor                   :: account_id(), %% account receive money/points
-		 currency                   :: currency(),   %% some of the points or money
-		 info                       :: transaction_info(),
-                 next,
-                 prev
-		 }).
+          id                         :: transaction_id(),
+          commit_time                :: erlang:now(),
+          amount                     :: integer(),    %% amount to move between accounts
+          remitter                   :: account_id(), %% accout that gives money/points
+          acceptor                   :: account_id(), %% account receive money/points
+          currency                   :: currency(),   %% some of the points or money
+          info                       :: transaction_info(),
+          next,
+          prev
+        }).
 
 %% Currencies
 
 -define(CURRENCY_KAKUSH,               kakush).
--define(CURRENCY_KAKUSH_CURRENCY,      kakush_currency). % used for gifts section, charged only when user buy package
+-define(CURRENCY_KAKUSH_CURRENCY,      kakush_currency). %% used for gifts section, charged only when user buy package
 -define(CURRENCY_MONEY,       money).
 -define(CURRENCY_GAME_POINTS, game_point).
 -define(CURRENCY_QUOTA,       quota).

+ 36 - 29
apps/db/include/scoring.hrl

@@ -1,34 +1,41 @@
--record(player_scoring, {
-    id,
-    temp, 
-    permanent, % top of Permanent Scoring record linked list
-    agregated_score %-- aggregated score for all game types is is a list
-                    %  [{game_okey, 15},{game_tavla, 12},...]
+-ifndef(SCORING_HRL).
+-define(SCORING_HRL, "scoring_hrl").
 
-    }).
+-include_lib("kvs/include/kvs.hrl").
+
+-record(player_scoring, {
+          ?ITERATOR(feed),
+          temp, 
+          permanent, %% top of Permanent Scoring record linked list
+          %%-- aggregated score for all game types is is a list
+          %%  [{game_okey, 15},{game_tavla, 12},...]
+          agregated_score 
+         }).
 
 -record(scoring_record, {
-    id,          % id of that record
-    next,        % next record for traversal
-    prev,
-    game_id,     % game id for rematching and lost connections
-    who,         % player
-    all_players, % with other players
-    game_type,   % okey, tavla, batak 
-    game_kind,   % chanak, standard, even-odd
-    condition,   % reveal with even tashes, color okey reveal, show gosterge, batak 3 aces, tavla mars.
-    score_points,       % result score points for player
-    score_kakaush,      % result score kakuş for player
-    custom,      % erlang record for a specific game
-    timestamp    % now() of the record
+          ?ITERATOR(feed),
+          game_id,     %% game id for rematching and lost connections
+          who,         %% player
+          all_players, %% with other players
+          game_type,   %% okey, tavla, batak 
+          game_kind,   %% chanak, standard, even-odd
+          condition,   %% reveal with even tashes, color okey reveal, show gosterge, batak 3 aces, tavla mars.
+          score_points,       %% result score points for player
+          score_kakaush,      %% result score kakuş for player
+          custom,      %% erlang record for a specific game
+          timestamp    %% now() of the record
     }).
 
--record(personal_score, { % total count of everything
-        uid,
-        games = 0,  
-        wins = 0,
-        loses = 0,
-        disconnects = 0,
-        points = 0,
-        average_time = 0
-    }).
+%% total count of everything
+-record(personal_score, { 
+          ?ITERATOR(feed),
+          uid,
+          games = 0,  
+          wins = 0,
+          loses = 0,
+          disconnects = 0,
+          points = 0,
+          average_time = 0
+         }).
+
+-endif.

+ 57 - 46
apps/db/include/table.hrl

@@ -1,48 +1,59 @@
--include("types.hrl").
+-ifndef(TABLE_HRL).
+-define(TABLE_HRL, "table.hrl").
 
--record(game_table, {id :: id_type() | '_', %% Dialyzer and record MatchSpec warnings http://j.mp/vZ8670
-                     name,
-                     gameid,
-                     trn_id,
-                     game_type,
-                     rounds :: integer() | 'undefined' | '_',
-                     sets :: integer() | 'undefined' | '_',
-                     owner :: username_type() | '_',
-                     timestamp,
-                     users = [] :: [username_type()] | '_',
-                     users_options = [] :: [username_type()] | '_',
-                     game_mode,
-                     game_options,
-                     game_speed,
-                     friends_only,
-                     invited_users = [] :: [username_type()] | '_',
-                     private :: boolean() | '_',
-                     feel_lucky = false :: boolean(),
-                     creator,
-                     age_limit,
-                     groups_only = [] :: [id_type()] | '_',
-                     gender_limit,
-                     location_limit = "",
-                     paid_only,
-                     deny_robots = false :: boolean() | '_',
-                     slang,
-                     deny_observers,
-                     gosterge_finish = false :: boolean() | '_',
-                     double_points = 1 :: integer(),
-                     game_state,
-                     game_process :: pid() | '_',
-                     game_module :: atom(),
-                     pointing_rules :: any() | '_', %% #pointing_rule{}
-                     pointing_rules_ex :: [] | '_', %% [#pointing_rule{}] - list of additional pointing rules,
-                                                    %% for example IFeelLucky for okey game
-                     game_process_monitor :: reference() | '_',
-                
-                     tournament_type = simple :: simple | paired | paired_lobby | tournament,
-                     robots_replacement_allowed = true :: boolean()
-    }).
+-include_lib("server/include/types.hrl").
+-include_lib("kvs/include/kvs.hrl").
 
--record(save_game_table, {uid :: username_type() | '_', %% Dialyzer and record MatchSpec warnings http://j.mp/vZ8670
-                          id :: id_type() | '_',
-                          name,
-                          create_time,
-                          settings}).
+-record(game_table, 
+        {
+          ?ITERATOR(feed),
+          name,
+          gameid,
+          trn_id,
+          game_type,
+          rounds :: integer() | 'undefined' | '_',
+          sets :: integer() | 'undefined' | '_',
+          owner :: username_type() | '_',
+          timestamp,
+          users = [] :: [username_type()] | '_',
+          users_options = [] :: [username_type()] | '_',
+          game_mode,
+          game_options,
+          game_speed,
+          friends_only,
+          invited_users = [] :: [username_type()] | '_',
+          private :: boolean() | '_',
+          feel_lucky = false :: boolean(),
+          creator,
+          age_limit,
+          groups_only = [] :: [id_type()] | '_',
+          gender_limit,
+          location_limit = "",
+          paid_only,
+          deny_robots = false :: boolean() | '_',
+          slang,
+          deny_observers,
+          gosterge_finish = false :: boolean() | '_',
+          double_points = 1 :: integer(),
+          game_state,
+          game_process :: pid() | '_',
+          game_module :: atom(),
+          pointing_rules :: any() | '_', %% #pointing_rule{}
+          pointing_rules_ex :: [] | '_', %% [#pointing_rule{}] - list of additional pointing rules,
+          %% for example IFeelLucky for okey game
+          game_process_monitor :: reference() | '_',
+
+          tournament_type = simple :: simple | paired | paired_lobby | tournament,
+          robots_replacement_allowed = true :: boolean()
+        }).
+
+-record(save_game_table,
+        {
+          ?ITERATOR(feed),
+          uid :: username_type() | '_', %% Dialyzer and record MatchSpec warnings http://j.mp/vZ8670
+          name,
+          create_time,
+          settings
+         }
+       ).
+-endif.

+ 52 - 37
apps/db/include/tournaments.hrl

@@ -1,42 +1,57 @@
+-ifndef(TOURNAMENTS_HRL).
+-define(TOURNAMENTS_HRL, "tournaments.hrl").
+
+-include_lib("kvs/include/kvs.hrl").
+
 -record(team,
-        {name, % { team name for now will bu just first player username }
-         id,
-         play_record, % { linked list history of played users under that ticket }
-         type }).
+        {
+          ?ITERATOR(feed),
+          name, %% team name for now will bu just first player username
+          play_record, %% linked list history of played users under that ticket
+          type
+        }
+       ).
 
 -record(tournament,
-        {name, % { tournament name }
-         id,
-         game_type,
-         description,
-         creator,
-         created,
-         start_date,
-         start_time,
-         end_date,
-         status, % { activated, ongoing, finished, canceled }
-         quota,
-         tours,
-         awards, 
-         winners :: list(), % [{UserId, Position, GiftId}]
-         waiting_queue, % { play_record, added here when user wants to join tournament }
-         avatar,
-         owner,
-         players_count,
-         speed,
-         type,
-         game_mode }). % { eliminatin, pointing, etc }
-
--record(play_record, % { tournament_player, game_record, tournament_info, choose your name :) }
-        {who, % { user }
-         tournament, % { tournament in which user played }
-         team, % { team under which user player tournament }
-         game_id, % { game id that user played under that team }
+        {
+          ?ITERATOR(feed),
+          name, %% tournament name
+          game_type,
+          description,
+          creator,
+          created,
+          start_date,
+          start_time,
+          end_date,
+          status, %% activated, ongoing, finished, canceled
+          quota,
+          tours,
+          awards, 
+          winners :: list(), %% [{UserId, Position, GiftId}]
+          waiting_queue, %% play_record, added here when user wants to join tournament
+          avatar,
+          owner,
+          players_count,
+          speed,
+          type,
+          game_mode
+        }
+       ). %% eliminatin, pointing, etc
 
-         realname,
-         game_points,
-         kakush,
-         kakush_currency,
-         quota,
-         other }).
+-record(play_record, %% tournament_player, game_record, tournament_info, choose your name :)
+        {
+          ?ITERATOR(feed),
+          who, %% user
+          tournament, %% tournament in which user played
+          team, %% team under which user player tournament
+          game_id, %% game id that user played under that team
+          realname,
+          game_points,
+          kakush,
+          kakush_currency,
+          quota,
+          other
+        }
+       ).
 
+-endif.

+ 5 - 0
apps/db/include/user.hrl

@@ -1,3 +1,6 @@
+-ifndef(USERS_HRL).
+-define(USERS_HRL, "users.hrl").
+
 -include("types.hrl").
 
 -record(user_status,
@@ -129,3 +132,5 @@
 %% Group exchange name
 -define(GROUP_EXCHANGE(GroupId),
         list_to_binary("group_exchange."++GroupId++".fanout")).
+
+-endif.

+ 12 - 0
apps/db/src/db_accounts.erl

@@ -0,0 +1,12 @@
+-module(db_accounts).
+-include_lib("kvs/include/metainfo.hrl").
+-include_lib("db/include/accounts.hrl").
+-compile(export_all).
+
+metainfo() ->
+    #schema{name = kvs, tables = 
+                [
+                 #table{name = account, fields=record_info(fields, account)},
+                 #table{name = pointing_rule, fields=record_info(fields, pointing_rule)}
+                ]
+           }.

+ 13 - 0
apps/db/src/db_scoring.erl

@@ -0,0 +1,13 @@
+-module(db_scoring).
+-include_lib("kvs/include/metainfo.hrl").
+-include_lib("db/include/scoring.hrl").
+-compile(export_all).
+
+metainfo() ->
+    #schema{name = kvs, tables = 
+                [
+                 #table{name = player_scoring, fields=record_info(fields, player_scoring)},
+                 #table{name = scoring_record, fields=record_info(fields, scoring_record)},
+                 #table{name = personal_score, fields=record_info(fields, personal_score)}
+                ]
+           }.

+ 12 - 0
apps/db/src/db_tabes.erl

@@ -0,0 +1,12 @@
+-module(db_tabes).
+-include_lib("kvs/include/metainfo.hrl").
+-include_lib("db/include/table.hrl").
+-compile(export_all).
+
+metainfo() ->
+    #schema{name = kvs, tables = 
+                [
+                 #table{name = game_table, fields=record_info(fields, game_table)},
+                 #table{name = save_game_table, fields=record_info(fields, save_game_table)}
+                ]
+           }.

+ 13 - 0
apps/db/src/db_tournaments.erl

@@ -0,0 +1,13 @@
+-module(db_tournaments).
+-include_lib("kvs/include/metainfo.hrl").
+-include_lib("db/include/tournaments.hrl").
+-compile(export_all).
+
+metainfo() ->
+    #schema{name = kvs, tables = 
+                [
+                 #table{name = team, fields=record_info(fields, team)},
+                 #table{name = tournament, fields=record_info(fields, tournament)},
+                 #table{name = play_record, fields=record_info(fields, play_record)}
+                ]
+           }.

+ 1 - 1
rels/web/files/sys.config

@@ -6,7 +6,7 @@
      [{pass_init_db,true},
       {nodes,[]},
       {dba, store_mnesia},
-      {schema, [kvs_user, kvs_acl, kvs_feed, kvs_subscription, db_config ]}]},
+      {schema, [kvs_user, kvs_acl, kvs_feed, kvs_subscription, db_config, db_scoring, db_accounts, db_tabes, db_tournaments ]}]},
  {sasl, [
          {sasl_error_logger, {file, "log/sasl-error.log"}},
          {errlog_type, error},