• R/O
  • SSH
  • HTTPS

jinrousiki: コミット


コミットメタ情報

リビジョン2780 (tree)
日時2021-08-17 20:52:52
作者umethyl

ログメッセージ

UserManagerController::RunCommand() 例外型に変更

変更サマリ

差分

--- trunk/include/controller/user_manager_class.php (revision 2779)
+++ trunk/include/controller/user_manager_class.php (revision 2780)
@@ -32,200 +32,207 @@
3232 }
3333
3434 //ブラックリストチェック
35- if (! ServerConfig::DEBUG_MODE && Security::IsLoginBlackList($trip)) {
35+ if (false === ServerConfig::DEBUG_MODE && Security::IsLoginBlackList($trip)) {
3636 self::OutputError(UserManagerMessage::BLACK_LIST_TITLE, UserManagerMessage::BLACK_LIST);
3737 }
3838
39- //記入漏れチェック
40- $title = UserManagerMessage::ERROR_INPUT;
41- $str = UserManagerMessage::ERROR_INPUT_TEXT . $back_url;
42- $empty = UserManagerMessage::ERROR_INPUT_EMPTY . $back_url;
43- if ($user_no < 1) {
44- if ($uname == '') {
45- self::OutputError($title, UserManagerMessage::UNAME . $str);
39+ try {
40+ //記入漏れチェック
41+ if ($user_no < 1) {
42+ if ($uname == '') {
43+ $error = UserManagerMessage::UNAME . UserManagerMessage::ERROR_INPUT_TEXT;
44+ throw new UnexpectedValueException($error);
45+ }
46+ if ($password == '') {
47+ $error = UserManagerMessage::PASSWORD . UserManagerMessage::ERROR_INPUT_TEXT;
48+ throw new UnexpectedValueException($error);
49+ }
4650 }
47- if ($password == '') {
48- self::OutputError($title, UserManagerMessage::PASSWORD . $str);
51+ if ($handle_name == '') {
52+ $error = UserManagerMessage::HANDLE_NAME . UserManagerMessage::ERROR_INPUT_TEXT;
53+ throw new UnexpectedValueException($error);
4954 }
50- }
51- if ($handle_name == '') {
52- self::OutputError($title, UserManagerMessage::HANDLE_NAME . $str);
53- }
54- if (empty($sex)) {
55- self::OutputError($title, UserManagerMessage::SEX . $empty);
56- }
57- if (empty($role)) {
58- self::OutputError($title, UserManagerMessage::WISH_ROLE . $empty);
59- }
60- if (false === is_int($icon_no)) {
61- self::OutputError($title, UserManagerMessage::ICON_NUMBER . $empty);
62- }
55+ if (empty($sex)) {
56+ $error = UserManagerMessage::SEX . UserManagerMessage::ERROR_INPUT_EMPTY;
57+ throw new UnexpectedValueException($error);
58+ }
59+ if (empty($role)) {
60+ $error = UserManagerMessage::WISH_ROLE . UserManagerMessage::ERROR_INPUT_EMPTY;
61+ throw new UnexpectedValueException($error);
62+ }
63+ if (false === is_int($icon_no)) {
64+ $error = UserManagerMessage::ICON_NUMBER . UserManagerMessage::ERROR_INPUT_EMPTY;
65+ throw new UnexpectedValueException($error);
66+ }
6367
64- //文字数制限チェック
65- $format = UserManagerMessage::ERROR_TEXT_LIMIT . $back_url;
66- $limit_list = [
67- ['str' => $uname,
68- 'name' => UserManagerMessage::UNAME,
69- 'config' => GameConfig::LIMIT_UNAME],
70- ['str' => $handle_name,
71- 'name' => UserManagerMessage::HANDLE_NAME,
72- 'config' => GameConfig::LIMIT_UNAME],
73- ['str' => $profile,
74- 'name' => UserManagerMessage::PROFILE,
75- 'config' => GameConfig::LIMIT_PROFILE]
76- ];
77- foreach ($limit_list as $limit) {
78- if (Text::Over($limit['str'], $limit['config'])) {
79- self::OutputError($title, sprintf($format, $limit['name'], $limit['config']));
68+ //文字数制限チェック
69+ $format = UserManagerMessage::ERROR_TEXT_LIMIT;
70+ $limit_list = [
71+ ['str' => $uname,
72+ 'name' => UserManagerMessage::UNAME,
73+ 'config' => GameConfig::LIMIT_UNAME],
74+ ['str' => $handle_name,
75+ 'name' => UserManagerMessage::HANDLE_NAME,
76+ 'config' => GameConfig::LIMIT_UNAME],
77+ ['str' => $profile,
78+ 'name' => UserManagerMessage::PROFILE,
79+ 'config' => GameConfig::LIMIT_PROFILE]
80+ ];
81+ foreach ($limit_list as $limit) {
82+ if (Text::Over($limit['str'], $limit['config'])) {
83+ throw new UnexpectedValueException(sprintf($format, $limit['name'], $limit['config']));
84+ }
8085 }
81- }
86+ unset($format);
8287
83- //例外チェック
84- if ($uname == GM::SYSTEM || $uname == GM::DUMMY_BOY) {
85- self::OutputError($title, sprintf(UserManagerMessage::CHECK_UNAME . $back_url, $uname));
86- }
87- if ($user_no < 1 && self::IsSystemName($handle_name)) {
88- $format = UserManagerMessage::CHECK_HANDLE_NAME;
89- self::OutputError($title, sprintf($format . $back_url, $handle_name));
90- }
91- if (! Sex::Exists($sex)) {
92- self::OutputError($title, UserManagerMessage::CHECK_SEX . $back_url);
93- }
94- if ($icon_no < ($user_no > 0 ? 0 : 1) || IconDB::Disable($icon_no)) {
95- /* ロック前なのでスキマが存在するが、実用性を考慮してここで判定する */
96- self::OutputError($title, UserManagerMessage::CHECK_ICON . $back_url);
97- }
88+ //例外チェック
89+ if ($uname == GM::SYSTEM || $uname == GM::DUMMY_BOY) {
90+ throw new UnexpectedValueException(sprintf(UserManagerMessage::CHECK_UNAME, $uname));
91+ }
92+ if ($user_no < 1 && self::IsSystemName($handle_name)) {
93+ $error = sprintf(UserManagerMessage::CHECK_HANDLE_NAME, $handle_name);
94+ throw new UnexpectedValueException($error);
95+ }
96+ if (false === Sex::Exists($sex)) {
97+ throw new UnexpectedValueException(UserManagerMessage::CHECK_SEX);
98+ }
99+ if ($icon_no < ($user_no > 0 ? 0 : 1) || IconDB::Disable($icon_no)) {
100+ /* ロック前なのでスキマが存在するが、実用性を考慮してここで判定する */
101+ throw new UnexpectedValueException(UserManagerMessage::CHECK_ICON);
102+ }
98103
99- if (! DB::Transaction()) { //トランザクション開始
100- self::OutputError(Message::DB_ERROR, Message::DB_ERROR_LOAD . $back_url);
101- }
104+ if (false === DB::Transaction()) { //トランザクション開始
105+ self::OutputError(Message::DB_ERROR, Message::DB_ERROR_LOAD . $back_url);
106+ }
102107
103- DB::SetRoom(RoomLoaderDB::LoadEntryUser($room_no)); //現在の村情報を取得 (ロック付き)
104- if (DB::$ROOM->IsClosing()) { //募集停止判定
105- if ($user_no < 1) { //入村済みならスキップ
106- self::OutputError(UserManagerMessage::LOGIN, UserManagerMessage::CLOSING);
108+ DB::SetRoom(RoomLoaderDB::LoadEntryUser($room_no)); //現在の村情報を取得 (ロック付き)
109+ if (DB::$ROOM->IsClosing()) { //募集停止判定
110+ if ($user_no < 1) { //入村済みならスキップ
111+ self::OutputError(UserManagerMessage::LOGIN, UserManagerMessage::CLOSING);
112+ }
113+ } elseif (false === DB::$ROOM->IsWaiting()) { //ゲーム開始判定
114+ self::OutputError(UserManagerMessage::LOGIN, UserManagerMessage::PLAYING);
107115 }
108- } elseif (! DB::$ROOM->IsWaiting()) { //ゲーム開始判定
109- self::OutputError(UserManagerMessage::LOGIN, UserManagerMessage::PLAYING);
110- }
111- DB::$ROOM->ParseOption(true);
116+ DB::$ROOM->ParseOption(true);
112117
113- //DB から現在のユーザ情報を取得 (ロック付き)
114- //ここで起動している Request クラスは Load 時の Requset_user_manager
115- RQ::Set(RequestDataGame::ID, $room_no);
116- RQ::Get('retrieve_type', 'entry_user');
117- DB::LoadUser();
118+ //DB から現在のユーザ情報を取得 (ロック付き)
119+ //ここで起動している Request クラスは Load 時の Requset_user_manager
120+ RQ::Set(RequestDataGame::ID, $room_no);
121+ RQ::Get('retrieve_type', 'entry_user');
122+ DB::LoadUser();
118123
119- //希望役職チェック
120- if (false === ArrayFilter::IsInclude(OptionManager::GetWishRoleList(), $role)) {
121- self::OutputError($title, UserManagerMessage::CHECK_WISH_ROLE . $back_url);
122- }
124+ //希望役職チェック
125+ if (false === ArrayFilter::IsInclude(OptionManager::GetWishRoleList(), $role)) {
126+ throw new UnexpectedValueException(UserManagerMessage::CHECK_WISH_ROLE);
127+ }
123128
124- $user_count = DB::$USER->Count(); //現在の KICK されていない住人の数を取得
125- if ($user_no < 1 && $user_count >= DB::$ROOM->max_user) { //定員オーバー判定
126- self::OutputError(UserManagerMessage::LOGIN, UserManagerMessage::MAX_USER);
127- }
129+ $user_count = DB::$USER->Count(); //現在の KICK されていない住人の数を取得
130+ if ($user_no < 1 && $user_count >= DB::$ROOM->max_user) { //定員オーバー判定
131+ self::OutputError(UserManagerMessage::LOGIN, UserManagerMessage::MAX_USER);
132+ }
128133
129- //重複チェック (比較演算子は大文字・小文字を区別しないのでクエリで直に判定する)
130- $footer = Text::BRLF . UserManagerMessage::ERROR_INPUT_FOOTER . $back_url;
134+ //重複チェック (比較演算子は大文字・小文字を区別しないのでクエリで直に判定する)
135+ $footer = Text::BRLF . UserManagerMessage::ERROR_INPUT_FOOTER;
131136
132- if ($user_no > 0) { //登録情報変更モード
133- $title = UserManagerMessage::CHANGE;
134- $target = UserDB::Load($user_no);
135- if ($target->session_id != Session::GetID()) {
136- self::OutputError(Message::SESSION_ERROR, UserManagerMessage::SESSION);
137- }
138- $target->room_no = RQ::Get()->room_no;
137+ if ($user_no > 0) { //登録情報変更モード
138+ $title = UserManagerMessage::CHANGE;
139+ $target = UserDB::Load($user_no);
140+ if ($target->session_id != Session::GetID()) {
141+ self::OutputError(Message::SESSION_ERROR, UserManagerMessage::SESSION);
142+ }
143+ $target->room_no = RQ::Get()->room_no;
139144
140- if (! $target->IsDummyBoy() && self::IsSystemName($handle_name)) {
141- $format = UserManagerMessage::CHECK_HANDLE_NAME;
142- self::OutputError($title, sprintf($format . $back_url, $handle_name));
143- }
145+ if (! $target->IsDummyBoy() && self::IsSystemName($handle_name)) {
146+ $format = UserManagerMessage::CHECK_HANDLE_NAME;
147+ self::OutputError($title, sprintf($format . $back_url, $handle_name));
148+ }
144149
145- if (UserDB::DuplicateName($user_no, $handle_name)) {
146- self::OutputError($title, UserManagerMessage::DUPLICATE_NAME . $footer);
147- }
150+ if (UserDB::DuplicateName($user_no, $handle_name)) {
151+ self::OutputError($title, UserManagerMessage::DUPLICATE_NAME . $footer);
152+ }
148153
149- $str = sprintf(UserManagerMessage::CHANGE_HEADER, $target->handle_name);
150- $stack = [];
151- if ($target->handle_name != $handle_name) {
152- $stack[RequestDataUser::HN] = $handle_name;
153- $format = Text::LF . UserManagerMessage::CHANGE_NAME;
154- $str .= sprintf($format, $target->handle_name, $handle_name);
155- }
156- if ($target->icon_no != $icon_no) {
157- if (! $target->IsDummyBoy() && $icon_no == 0) {
158- self::OutputError($title, UserManagerMessage::CHECK_ICON . $back_url);
154+ $str = sprintf(UserManagerMessage::CHANGE_HEADER, $target->handle_name);
155+ $stack = [];
156+ if ($target->handle_name != $handle_name) {
157+ $stack[RequestDataUser::HN] = $handle_name;
158+ $format = Text::LF . UserManagerMessage::CHANGE_NAME;
159+ $str .= sprintf($format, $target->handle_name, $handle_name);
159160 }
160- $stack[RequestDataIcon::ID] = $icon_no;
161- $format = Text::LF . UserManagerMessage::CHANGE_ICON;
162- $icon_name = IconDB::GetName($icon_no);
163- $str .= sprintf($format, $target->icon_no, $target->icon_name, $icon_no, $icon_name);
164- }
165- $value_list = [RequestDataUser::SEX, RequestDataUser::PROFILE, RequestDataUser::ROLE];
166- foreach ($value_list as $value) {
167- if ($target->$value != $$value) {
168- $stack[$value] = $$value;
161+ if ($target->icon_no != $icon_no) {
162+ if (! $target->IsDummyBoy() && $icon_no == 0) {
163+ self::OutputError($title, UserManagerMessage::CHECK_ICON . $back_url);
164+ }
165+ $stack[RequestDataIcon::ID] = $icon_no;
166+ $format = Text::LF . UserManagerMessage::CHANGE_ICON;
167+ $icon_name = IconDB::GetName($icon_no);
168+ $str .= sprintf($format, $target->icon_no, $target->icon_name, $icon_no, $icon_name);
169169 }
170+ $value_list = [RequestDataUser::SEX, RequestDataUser::PROFILE, RequestDataUser::ROLE];
171+ foreach ($value_list as $value) {
172+ if ($target->$value != $$value) {
173+ $stack[$value] = $$value;
174+ }
175+ }
176+
177+ if (count($stack) < 1) {
178+ self::OutputError($title, UserManagerMessage::CHANGE_NONE . $back_url);
179+ }
180+ RoomTalk::StoreBeforeGame($str, $target);
181+
182+ if ($target->UpdateList($stack) && DB::Commit()) {
183+ self::OutputError($title, HTML::GenerateCloseWindow(UserManagerMessage::CHANGE_SUCCESS));
184+ } else {
185+ self::OutputError(Message::DB_ERROR, Message::DB_ERROR_LOAD . $back_url);
186+ }
170187 }
171188
172- if (count($stack) < 1) {
173- self::OutputError($title, UserManagerMessage::CHANGE_NONE . $back_url);
189+ //ユーザ名・村人名
190+ OptionManager::ValidateUserEntryUname($uname);
191+ if (UserDB::IsKick($uname)) { //キックされた人と同じユーザ名
192+ throw new UnexpectedValueException(UserManagerMessage::ERROR_INPUT_KICK . $footer);
174193 }
175- RoomTalk::StoreBeforeGame($str, $target);
176194
177- if ($target->UpdateList($stack) && DB::Commit()) {
178- self::OutputError($title, HTML::GenerateCloseWindow(UserManagerMessage::CHANGE_SUCCESS));
179- } else {
180- self::OutputError(Message::DB_ERROR, Message::DB_ERROR_LOAD . $back_url);
195+ if (UserDB::Duplicate($uname, $handle_name)) { //ユーザ名・村人名重複
196+ $error = UserManagerMessage::DUPLICATE_NAME . $footer . $back_url;
197+ self::OutputError(UserManagerMessage::DUPLICATE, $error);
181198 }
182- }
183199
184- //ユーザ名・村人名
185- $error_message = OptionManager::ValidateUserEntryUname($uname);
186- if (null !== $error_message) {
187- self::OutputError($title, $error_message . $back_url);
188- }
200+ //IP アドレスチェック
201+ if (false === ServerConfig::DEBUG_MODE && GameConfig::LIMIT_IP && UserDB::DuplicateIP()) {
202+ $error = UserManagerMessage::DUPLICATE_IP . $back_url;
203+ self::OutputError(UserManagerMessage::DUPLICATE, $error);
204+ }
189205
190- if (UserDB::IsKick($uname)) { //キックされた人と同じユーザ名
191- self::OutputError($title, UserManagerMessage::ERROR_INPUT_KICK . $footer);
192- }
206+ //DB にユーザデータを登録
207+ $list = [
208+ 'room_no' => $room_no,
209+ 'user_no' => DB::$USER->CountAll() + 1, //KICK された住人も含めた新しい番号を振る
210+ 'uname' => $uname,
211+ 'handle_name' => $handle_name,
212+ 'icon_no' => $icon_no,
213+ 'profile' => $profile,
214+ 'sex' => $sex,
215+ 'password' => $password,
216+ 'role' => $role
217+ ];
193218
194- $title = UserManagerMessage::DUPLICATE; //多重登録判定
195- if (UserDB::Duplicate($uname, $handle_name)) { //ユーザ名・村人名重複
196- self::OutputError($title, UserManagerMessage::DUPLICATE_NAME . $footer);
197- }
219+ if (UserDB::Insert($list)) {
220+ JinrouCookie::Initialize(); //クッキーの初期化
221+ RoomTalk::StoreSystem(sprintf(TalkMessage::ENTRY_USER, $handle_name)); //入村メッセージ
222+ RoomDB::UpdateTime();
223+ DB::Commit();
198224
199- //IP アドレスチェック
200- if (! ServerConfig::DEBUG_MODE && GameConfig::LIMIT_IP && UserDB::DuplicateIP()) {
201- self::OutputError($title, UserManagerMessage::DUPLICATE_IP);
225+ $url = URL::GetRoom('game_frame', $room_no);
226+ $str = Text::Join(sprintf(UserManagerMessage::ENTRY, ++$user_count), URL::GetJump($url));
227+ HTML::OutputResult(UserManagerMessage::TITLE, $str, $url);
228+ } else {
229+ self::OutputError(Message::DB_ERROR, Message::DB_ERROR_LOAD);
230+ }
231+ } catch (UnexpectedValueException $e) {
232+ self::OutputError(UserManagerMessage::ERROR_INPUT, $e->getMessage() . $back_url);
233+ } catch (Exception $e) {
234+ self::OutputError(Message::DB_ERROR, $e->getMessage());
202235 }
203-
204- //DB にユーザデータを登録
205- $list = [
206- 'room_no' => $room_no,
207- 'user_no' => DB::$USER->CountAll() + 1, //KICK された住人も含めた新しい番号を振る
208- 'uname' => $uname,
209- 'handle_name' => $handle_name,
210- 'icon_no' => $icon_no,
211- 'profile' => $profile,
212- 'sex' => $sex,
213- 'password' => $password,
214- 'role' => $role
215- ];
216-
217- if (UserDB::Insert($list)) {
218- JinrouCookie::Initialize(); //クッキーの初期化
219- RoomTalk::StoreSystem(sprintf(TalkMessage::ENTRY_USER, $handle_name)); //入村メッセージ
220- RoomDB::UpdateTime();
221- DB::Commit();
222-
223- $url = URL::GetRoom('game_frame', $room_no);
224- $str = Text::Join(sprintf(UserManagerMessage::ENTRY, ++$user_count), URL::GetJump($url));
225- HTML::OutputResult(UserManagerMessage::TITLE, $str, $url);
226- } else {
227- self::OutputError(Message::DB_ERROR, Message::DB_ERROR_LOAD);
228- }
229236 }
230237
231238 protected static function Output() {
--- trunk/include/option/necessary_name.php (revision 2779)
+++ trunk/include/option/necessary_name.php (revision 2780)
@@ -37,9 +37,7 @@
3737 //ユーザー名入力エラーチェック
3838 public function ValidateUserEntryUname($uname) {
3939 if (Text::IsPrefix($uname, Message::TRIP)) {
40- return UserManagerMessage::ERROR_INPUT_UNAME;
41- } else {
42- return null;
40+ throw new UnexpectedValueException(UserManagerMessage::ERROR_INPUT_UNAME);
4341 }
4442 }
4543 }
--- trunk/include/option/necessary_trip.php (revision 2779)
+++ trunk/include/option/necessary_trip.php (revision 2780)
@@ -31,10 +31,8 @@
3131
3232 //ユーザー名入力エラーチェック
3333 public function ValidateUserEntryUname($uname) {
34- if (Text::Search($uname, Message::TRIP)) {
35- return null;
36- } else {
37- return UserManagerMessage::ERROR_INPUT_TRIP;
34+ if (false === Text::Search($uname, Message::TRIP)) {
35+ throw new UnexpectedValueException(UserManagerMessage::ERROR_INPUT_TRIP);
3836 }
3937 }
4038 }
旧リポジトリブラウザで表示