OSDN Git Service

17b393a445be8f939245562f861520e542c03e45
[internetcity/prototype.git] / common / CClientConnection.cpp
1 #include "CClientConnection.h"
2
3 ////////////////////////////////////////////////////////////////////////////////
4 // \83R\83\93\83X\83g\83\89\83N\83^
5 ////////////////////////////////////////////////////////////////////////////////
6 CClientConnection::CClientConnection()
7 {
8         m_isLogin = false;
9 }
10
11 ////////////////////////////////////////////////////////////////////////////////
12 // \83f\83X\83g\83\89\83N\83^
13 ////////////////////////////////////////////////////////////////////////////////
14 CClientConnection::~CClientConnection()
15 {
16 }
17
18 ////////////////////////////////////////////////////////////////////////////////
19 // initialize
20 ////////////////////////////////////////////////////////////////////////////////
21 bool CClientConnection::initialize()
22 {
23         CSocket::initialize();
24         return true;
25 }
26
27 ////////////////////////////////////////////////////////////////////////////////
28 // send
29 ////////////////////////////////////////////////////////////////////////////////
30 bool CClientConnection::send(const CommunicationData* in_pCommunicationData)
31 {
32         // \83T\83C\83Y\82Í\8c\88\82ß\91Å\82¿
33         if(::send(m_Socket, reinterpret_cast<const char*>(in_pCommunicationData), MAX_COMMUNICATION_DATA_LENGTH, 0) == SOCKET_ERROR){
34                 return false;
35         }
36         return true;
37 }
38
39 ////////////////////////////////////////////////////////////////////////////////
40 // receive
41 ////////////////////////////////////////////////////////////////////////////////
42 bool CClientConnection::receive(CommunicationData** out_ppCommunicationData)
43 {
44         if(m_Buffer.empty()){
45                 return false;
46         }
47
48         *out_ppCommunicationData = reinterpret_cast<CommunicationData*>(m_Buffer.getReadPointer()->m_Buffer);
49         m_Buffer.nextReadBuffer();
50         return true;
51 }
52
53 ////////////////////////////////////////////////////////////////////////////////
54 // login
55 ////////////////////////////////////////////////////////////////////////////////
56 bool CClientConnection::login(const char* in_pLoginName)
57 {
58         CommunicationData a_SendData;
59         a_SendData.m_DataType = 'i';
60         strcpy(a_SendData.m_Data.m_LoginData.m_Name, in_pLoginName);
61         send(&a_SendData);
62
63         // \82±\82Ì\83t\83\89\83O\82Í\8eó\90M\83\81\83b\83Z\81[\83W\82ð\8am\82©\82ß\82Ä\82©\82ç\95Ï\8dX\82·\82é\82×\82«
64         m_isLogin = true;
65         return true;
66 }
67
68 ////////////////////////////////////////////////////////////////////////////////
69 // logout
70 ////////////////////////////////////////////////////////////////////////////////
71 bool CClientConnection::logout()
72 {
73         CommunicationData a_SendData;
74         a_SendData.m_DataType = 'o';
75         send(&a_SendData);
76         return true;
77 }
78
79 ////////////////////////////////////////////////////////////////////////////////
80 // \8dÀ\95W\8eæ\93¾
81 ////////////////////////////////////////////////////////////////////////////////
82 bool CClientConnection::requestPosition()
83 {
84         CommunicationData a_SendData;
85         a_SendData.m_DataType = 'p';
86         send(&a_SendData);
87         return true;
88 }
89
90 ////////////////////////////////////////////////////////////////////////////////
91 // \88Ú\93®
92 ////////////////////////////////////////////////////////////////////////////////
93 bool CClientConnection::requestMove(char in_Direction)
94 {
95         CommunicationData a_SendData;
96         a_SendData.m_DataType = 'a';
97         a_SendData.m_Data.m_ActionCommand.m_CommandType = in_Direction;
98         send(&a_SendData);
99         return true;
100 }
101
102 ////////////////////////////////////////////////////////////////////////////////
103 // \89¹\90º\91\97\90M
104 ////////////////////////////////////////////////////////////////////////////////
105 bool CClientConnection::sendVoice(char* in_pVoice, int in_Length, bool in_isEnd)
106 {
107         CommunicationData a_SendData;
108
109         if(sizeof(a_SendData.m_Data.m_Voice.m_Stream) < in_Length){
110                 return false;
111         }
112
113         a_SendData.m_DataType = 'v';
114         for(int i = 0; i < in_Length; i++){
115                 a_SendData.m_Data.m_Voice.m_Stream[i] = in_pVoice[i];
116         }
117         a_SendData.m_Data.m_Voice.m_Length = in_Length;
118         a_SendData.m_Data.m_Voice.m_isEnd = in_isEnd;
119         send(&a_SendData);
120         return true;
121 }