📄 server.h
字号:
// server.h : main header file for the SERVER application
//
#if !defined(AFX_SERVER_H__74FF87E9_5BEC_11D4_B516_00A024ECD38F__INCLUDED_)
#define AFX_SERVER_H__74FF87E9_5BEC_11D4_B516_00A024ECD38F__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
#define MAX_NAME 14
#define MAX_IP 16
#define MAX_CHAT 36
#define MAX_GAMESERVER 25
#define MAX_MESSAGE 1024
#define MAX_SCORE 20
#include "resource.h" // main symbols
#include "serversocket.h"
#include "receivesocket.h"
#include "mainfrm.h"
/////////////////////////////////////////////////////////////////////////////
// CServerApp:
// See server.cpp for the implementation of this class
//
//服务器与Client公用的结构体
//---------------------------------------------------------//
#define MSGTYPE_LOGIN 100
#define MSGTYPE_EXIT 102
#define MSGTYPE_CHAT 104
#define MSGTYPE_GAMESERVERLIST 106
#define MSGTYPE_CREATEGAME 108
#define MSGTYPE_RUNGAME 110
#define MSGTYPE_CANCELGAME 112
#define MSGTYPE_GETSCORER 113
#define MSGTYPE_GETONLINE 114
#define MSGTYPE_SCORER 115
#define MSGTYPE_ONLINE 116
#define MSGTYPE_PLAYERIN 117
#define MSGTYPE_PLAYEROUT 118
#define MSGTYPE_PLAYERRUNGAME 119
#ifndef TAG_MESSAGE
typedef struct tag_LoginInfo
{
char MsgType;
char ch_Name[MAX_NAME]; //名字最长为12个字母
}LOGIN_INFO;
typedef struct tag_Chat
{
char MsgType;
char ch_Content[MAX_CHAT];
}CHAT_INFO;
typedef struct tag_Scorer
{
char MsgType;
char ScorerName[MAX_SCORE][MAX_NAME];
long Score[MAX_SCORE][3];
}SCORER_INFO;
#define TAG_MESSAGE
#endif
//--------------------------------------------------------//
#define MAX_CONNECTION 300
#ifndef TAG_PLAYERLIST
typedef struct tag_PlayerInfo
{
CReceiveSocket *cs_ClientPtr;
}PLAYER_INFO;
typedef struct tag_MsgBuffer
{
char *MsgBufferPtr;
CReceiveSocket *cs_Player;
}MSG_BUFFER;
#define TAG_PLAYERLIST
#endif
#define MAX_MESSAGEBUFFER 100
class CServerApp : public CWinApp
{
public:
CServerApp();
UINT uint_nPort;
char ch_HostName[20];
char ch_HostAdr[20];
CServerSocket *cs_Server;
PLAYER_INFO PlayerInfo[MAX_CONNECTION];
MSG_BUFFER MsgBuffer[MAX_MESSAGEBUFFER];
SCORER_INFO ScorerInfo;
int MsgBufferCount;
int PlayerCount;
BOOL AddNewPlayer();
BOOL GetNewPlayerName(CReceiveSocket *cs_Client);
BOOL DeletePlayer(CReceiveSocket *cs_Player);
BOOL CreateServerSocket();
BOOL SendPlayerChatMsg(char *ch_ChatMsg,CReceiveSocket *cs_Player);
BOOL SendGameListMsg(CReceiveSocket *cs_Client,BOOL bo_ToAll);
void EndServerSocket();
BOOL PlayerAdding;
BOOL HandleMessageBuffer();
BOOL GetMessageFromPlayerSocket();
void ReadScoreRecordFromFile(char *FileName);
void SendScorer(CReceiveSocket *cs_Player);
void SendNewPlayerToAll(CReceiveSocket *cs_Player);
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CServerApp)
public:
virtual BOOL InitInstance();
virtual int ExitInstance();
virtual BOOL OnIdle(LONG lCount);
//}}AFX_VIRTUAL
// Implementation
//{{AFX_MSG(CServerApp)
afx_msg void OnAppAbout();
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
extern CServerApp theApp;
extern CMainFrame *pFrame;
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_SERVER_H__74FF87E9_5BEC_11D4_B516_00A024ECD38F__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -