• R/O
  • SSH
  • HTTPS

mhack: 提交


Commit MetaInfo

修订版26 (tree)
时间2010-03-28 22:54:42
作者satofumi

Log Message

ユーザ入力の処理ハンドラを追加

更改概述

差异

--- trunk/server/UserInput.cpp (nonexistent)
+++ trunk/server/UserInput.cpp (revision 26)
@@ -0,0 +1,90 @@
1+/*!
2+ \file
3+ \brief ユーザ入力の受け付け
4+
5+ \author Satofumi KAMIMURA
6+
7+ $Id$
8+*/
9+
10+#include "UserInput.h"
11+#include "TcpipSocket.h"
12+
13+using namespace qrk;
14+
15+
16+struct UserInput::pImpl
17+{
18+ TcpipSocket* socket_;
19+ bool disconnected_;
20+
21+
22+ pImpl(TcpipSocket* socket) : socket_(socket), disconnected_(false)
23+ {
24+ }
25+};
26+
27+
28+UserInput::UserInput(TcpipSocket* socket) : pimpl(new pImpl(socket))
29+{
30+}
31+
32+
33+UserInput::~UserInput(void)
34+{
35+}
36+
37+
38+bool UserInput::isChanged(void)
39+{
40+ // TcpipSocket を評価して、適切なデータを受信したら true を返す
41+ enum {
42+ BufferSize = 1024,
43+ };
44+ char buffer[BufferSize];
45+
46+ int n = pimpl->socket_->receive(buffer, BufferSize, 0);
47+ if (n < 0) {
48+ pimpl->disconnected_ = true;
49+ return true;
50+ }
51+
52+ // 受信データのパースと登録
53+ // !!!
54+
55+ return false;
56+}
57+
58+
59+bool UserInput::disconnected(void)
60+{
61+ return pimpl->disconnected_;
62+}
63+
64+
65+void UserInput::command(const std::string& command)
66+{
67+ (void)command;
68+ // !!!
69+}
70+
71+
72+void UserInput::moveTarget(const Point<long>& point)
73+{
74+ (void)point;
75+ // !!!
76+}
77+
78+
79+void UserInput::attackTarget(const Point<long>& point)
80+{
81+ (void)point;
82+ // !!!
83+}
84+
85+
86+void UserInput::chatMessage(const std::string& message)
87+{
88+ (void)message;
89+ // !!!
90+}
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
--- trunk/server/Character.h (revision 25)
+++ trunk/server/Character.h (revision 26)
@@ -10,6 +10,7 @@
1010 $Id$
1111 */
1212
13+
1314 class Character
1415 {
1516 public:
--- trunk/server/Users.cpp (revision 25)
+++ trunk/server/Users.cpp (revision 26)
@@ -8,10 +8,87 @@
88 */
99
1010 #include "Users.h"
11+#include "UserInput.h"
12+#include "TcpipAccepter.h"
13+#include <vector>
1114
15+using namespace qrk;
16+using namespace std;
1217
18+
19+typedef vector<UserInput*> UserInputs;
20+
21+struct Users::pImpl
22+{
23+ TcpipAccepter tcpip_accepter_;
24+ UserInputs users_;
25+
26+
27+ void acceptNewConnection(void)
28+ {
29+ TcpipSocket* socket = tcpip_accepter_.accept();
30+ if (! socket) {
31+ // 新規接続なし
32+ return;
33+ }
34+
35+ // !!! users_ 中に同じキャラクタ ID が自動操作で存在したら、
36+ // !!! そのキャラクタ ID を使うようにする
37+
38+ // !!! キャラクタと操作を結びつける何かの設定
39+
40+ users_.push_back(new UserInput(socket));
41+ }
42+};
43+
44+
45+Users::Users(void) : pimpl(new pImpl)
46+{
47+}
48+
49+
50+Users::~Users(void)
51+{
52+}
53+
54+
55+bool Users::acitvate(unsigned short port)
56+{
57+ return pimpl->tcpip_accepter_.activate(port);
58+}
59+
60+
1361 void Users::update(EventManager& event_manager)
1462 {
63+ // 新規接続の追加
64+ pimpl->acceptNewConnection();
65+
66+ // 既存のユーザ処理
67+ for (UserInputs::iterator it = pimpl->users_.begin();
68+ it != pimpl->users_.end(); ++it) {
69+ if (! (*it)->isChanged()) {
70+ continue;
71+ }
72+
73+ if ((*it)->disconnected()) {
74+ if (0) {
75+ // 手動操作のときは、キャラクタの帰宅するよう設定する
76+ // !!!
77+ }
78+
79+ // ユーザ操作の切断処理
80+ swap(*it, pimpl->users_.back());
81+ pimpl->users_.pop_back();
82+ --it;
83+ continue;
84+ }
85+
86+ // !!! - キャラクター作成まわり
87+ // !!! - マップ内の移動
88+ // !!! - アイテムの売買
89+ }
90+
91+ // イベントの更新
1592 (void)event_manager;
1693 // !!!
1794 }
--- trunk/server/UserInput.h (nonexistent)
+++ trunk/server/UserInput.h (revision 26)
@@ -0,0 +1,45 @@
1+#ifndef USER_INPUT_H
2+#define USER_INPUT_H
3+
4+/*!
5+ \file
6+ \brief ユーザ入力の受け付け
7+
8+ \author Satofumi KAMIMURA
9+
10+ $Id$
11+*/
12+
13+#include "Input.h"
14+#include <memory>
15+
16+
17+namespace qrk
18+{
19+ class TcpipSocket;
20+}
21+
22+
23+class UserInput : public Input
24+{
25+public:
26+ UserInput(qrk::TcpipSocket* socket);
27+ ~UserInput(void);
28+
29+ bool isChanged(void);
30+ bool disconnected(void);
31+ void command(const std::string& command);
32+ void moveTarget(const qrk::Point<long>& point);
33+ void attackTarget(const qrk::Point<long>& point);
34+ void chatMessage(const std::string& message);
35+
36+private:
37+ UserInput(void);
38+ UserInput(const UserInput& rhs);
39+ UserInput& operator = (const UserInput& rhs);
40+
41+ struct pImpl;
42+ std::auto_ptr<pImpl> pimpl;
43+};
44+
45+#endif /* !USER_INPUT_H */
Added: svn:keywords
## -0,0 +1 ##
+Id
\ No newline at end of property
--- trunk/server/Input.h (revision 25)
+++ trunk/server/Input.h (revision 26)
@@ -10,6 +10,10 @@
1010 $Id$
1111 */
1212
13+#include "Point.h"
14+#include <string>
15+
16+
1317 class Input
1418 {
1519 public:
@@ -17,7 +21,17 @@
1721 {
1822 }
1923
20- // !!!
24+
25+ virtual bool isChanged(void) = 0;
26+
27+ virtual bool disconnected(void) = 0;
28+
29+ virtual void command(const std::string& command) = 0;
30+
31+ virtual void moveTarget(const qrk::Point<long>& point) = 0;
32+ virtual void attackTarget(const qrk::Point<long>& point) = 0;
33+
34+ virtual void chatMessage(const std::string& message) = 0;
2135 };
2236
2337 #endif /* !INPUT_H */
--- trunk/server/Users.h (revision 25)
+++ trunk/server/Users.h (revision 26)
@@ -10,6 +10,8 @@
1010 $Id$
1111 */
1212
13+#include <memory>
14+
1315 class EventManager;
1416
1517
@@ -16,10 +18,20 @@
1618 class Users
1719 {
1820 public:
19- // !!!
21+ Users(void);
22+ ~Users(void);
2023
24+ bool acitvate(unsigned short port);
2125
2226 void update(EventManager& event_manager);
27+
28+
29+private:
30+ Users(const Users& rhs);
31+ Users& operator = (const Users& rhs);
32+
33+ struct pImpl;
34+ std::auto_ptr<pImpl> pimpl;
2335 };
2436
2537 #endif /* !USERS_H */
--- trunk/server/mhack_server.cpp (revision 25)
+++ trunk/server/mhack_server.cpp (revision 26)
@@ -22,7 +22,7 @@
2222
2323 namespace
2424 {
25- class Args
25+ class ArgsInformation
2626 {
2727 public:
2828
@@ -30,12 +30,12 @@
3030 };
3131
3232
33- Args parseArgs(int argc, char *argv[])
33+ ArgsInformation parseArgs(int argc, char *argv[])
3434 {
3535 (void)argc;
3636 (void)argv;
3737
38- Args args;
38+ ArgsInformation args;
3939 // !!!
4040
4141 return args;
@@ -75,7 +75,7 @@
7575
7676 int main(int argc, char *argv[])
7777 {
78- Args args = parseArgs(argc, argv);
78+ ArgsInformation args = parseArgs(argc, argv);
7979
8080 WorldMap world_map;
8181 if (! loadWorldMap(world_map)) {
@@ -108,5 +108,6 @@
108108 } while (command_console.quit());
109109
110110 log_printf("Program exit normally.");
111+
111112 return 0;
112113 }
--- trunk/server/MoveEvent.h (revision 25)
+++ trunk/server/MoveEvent.h (revision 26)
@@ -22,6 +22,7 @@
2222
2323 void action(void);
2424
25+
2526 private:
2627 MoveEvent(const MoveEvent& rhs);
2728 MoveEvent& operator = (const MoveEvent& rhs);
--- trunk/server/GroundObject.h (revision 25)
+++ trunk/server/GroundObject.h (revision 26)
@@ -17,6 +17,7 @@
1717 // !!! 種類毎の、破壊にかかるコスト
1818 // !!! 破壊が指定されたときに表示されるメッセージ
1919
20+
2021 GroundObject(void)
2122 {
2223 }
--- trunk/server/Makefile (revision 25)
+++ trunk/server/Makefile (revision 26)
@@ -4,9 +4,9 @@
44
55 CC = g++
66 CXXFLAGS = -g -O0 -Wall -W -Werror $(INCLUDES)
7-INCLUDES = -I$(LIB_DIR)/system
7+INCLUDES = -I$(LIB_DIR)/system -I$(LIB_DIR)/geometry -I$(LIB_DIR)/connection
88 LDFLAGS =
9-LDLIBS = `sdl-config --libs`
9+LDLIBS = `sdl-config --libs` -lSDL_net
1010
1111
1212 TARGET = mhack_server
@@ -21,8 +21,8 @@
2121
2222 .PHONY : all clean depend
2323 ######################################################################
24-OBJS = EventManager.o MoveEvent.o Users.o CommandConsole.o
25-REQUIRE_LIBS = $(LIB_DIR)/system/system.a $(LIB_DIR)/system/sdl/system_sdl.a
24+OBJS = EventManager.o MoveEvent.o Users.o UserInput.o CommandConsole.o
25+REQUIRE_LIBS = $(LIB_DIR)/connection/sdl/connection_sdl.a $(LIB_DIR)/system/system.a $(LIB_DIR)/system/sdl/system_sdl.a
2626
2727 $(REQUIRE_LIBS) :
2828 cd $(@D)/ && $(MAKE) $(@F)
@@ -35,12 +35,18 @@
3535 Dungeon.o: Floor.h GroundTile.h GroundObject.h Item.h
3636 Floor.o: GroundTile.h GroundObject.h Item.h
3737 GroundTile.o: GroundObject.h Item.h
38+Input.o: ../../../libs/geometry/Point.h
3839 MoveEvent.o: Event.h
40+UserInput.o: Input.h ../../../libs/geometry/Point.h
3941 WorldMap.o: GroundTile.h GroundObject.h Item.h Dungeon.h Floor.h
4042 CommandConsole.o: CommandConsole.h
4143 EventManager.o: EventManager.h
4244 MoveEvent.o: MoveEvent.h Event.h
43-Users.o: Users.h
45+UserInput.o: UserInput.h Input.h ../../../libs/geometry/Point.h
46+UserInput.o: ../../../libs/connection/TcpipSocket.h
47+UserInput.o: ../../../libs/connection/Connection.h
48+Users.o: Users.h UserInput.h Input.h ../../../libs/geometry/Point.h
49+Users.o: ../../../libs/connection/TcpipAccepter.h
4450 mhack_server.o: WorldMap.h GroundTile.h GroundObject.h Item.h Dungeon.h
4551 mhack_server.o: Floor.h Character.h EventManager.h Users.h CommandConsole.h
4652 mhack_server.o: ../../../libs/system/CycleTimer.h
Show on old repository browser