📄 network.h
字号:
/*
* ============================================================================
* Name : Network from Network.h
* Part of : Engine
* Created : 2005-03-24 Qiu Li
* Description:
* Declares main function of the network.
* Version :
* Copyright: Gameloft S.A.
* ============================================================================
*/
#ifndef NETWORK_H
#define NETWORK_H
#include "AEEWeb.h"
class CEngine;
//////////////////////////////////////////////////////////////////////////
// for online definition //
//////////////////////////////////////////////////////////////////////////
#define TIME_OUT 120000
#define TIME_LINK_IDLE 5000
#define STREQ(a,b) (!STRCMP(a,b))
#define GETPSEUDO "GETPSEUDO="
#define UID "UID="
#define NICK "NICK="
#define GID "GID="
#define NEXT_SEQ "NEXT_SEQ="
#define CHALLENGE "CHALLENGE="
#define ACCEPT_CHALLENGE "ACCEPT_CHALLENGE="
#define UCLEAR "UCLEAR="
#define GETINFO "GETINFO="
#define LOGIN "LOGIN=1"
#define AVERANK "AVERANK"
#define RESETPRO "RESET="
#define WINRANK "WINRANK"
#define HIGHRANK "HIGH"
//////////////////////////////////
// Online url name
//////////////////////////////////
#define ONLINE_URL_NAME "url.bar"
#define MAX_RANK_NUM 10
typedef struct RANK_DATA_
{
char name[11];
int score;
}RANK_DATA;
#define LINK_NONE 0
#define LINK_IDLE 1
#define LINK_CHALLENGE 2
#define LINK_WAITING 3
#define LINK_A_CHALLENGE 4
#define LINK_GAME_RUN 5
#define LINK_CHECK 6
#define LINK_GETNAME 7
#define LINK_GETOPNAME 8
//#define LINK_GAME_CHECK 8
#define LINK_CLEAR 9
#define LINK_GETINFO 10
#define LINK_LOGIN 11
#define LINK_SETNAME 12
#define LINK_GETAVERANK 13
#define LINK_RESET 14
#define LINK_GETWINRANK 15
#define LINK_GETHIGHRANK 16
#define WEB_MURL 0
#define WEB_OPEN 1
#define WEB_PARSE 2
#define WEB_IDLE 3//waitting for the web result or other thing
//#define GS_INIT 0
//#define GS_SETSERVER 1
//#define GS_SETUSER 2
//#define GS_WEBRUN 3
//#define GS_END 4
#define WEB_STATE_NONE 0
#define WEB_STATE_GETNICKNAME 1
#define WEB_STATE_SETNICKNAME 2
#define WEB_STATE_GETRIVAL 3
#define WEB_STATE_WANTCHALLENGE 4
#define WEB_STATE_SENDSCORE 5
#define WEB_STATE_RECEIVESCORE 6
#define WEB_STATE_INIT 7
#define WEB_STATE_KEEPCONNECT 8
#define WEB_STATE_GETINFO 9
#define WEB_STATE_LOGIN 10
#define WEB_STATE_GETAVERANK 11
#define WEB_STATE_GETGAMERESULT 12
#define WEB_STATE_RESETPROFILE 13
#define WEB_STATE_GETWINRANK 14
#define WEB_STATE_GETHIGHRANK 15
#define CHALLENGE_REJECTED 0
#define CHALLENGE_ACCEPTED 1
#define CHALLENGE_WAIT 2
#define SCORE_NONE 0
#define SCORE_SEND 1
#define SCORE_WAITRIVAL 2
#define SCORE_RECEIVERIVAL 3
#define LINK_ERROR_LOSTOP -2
#define LINK_ERROR_TIMEOUT -3
#define LINK_ERROR_RESULT -4
#define LINK_ERROR_CANNOT_ACCEPT_WHEN_CHAL -5
#define LINK_ERROR_CANNOT_CHAL_WHEN_ACCEPT -6
#define LINK_ERROR_LOGIN -7
#define LINK_ERROR_SETNICK -8
#define LINK_ERROR_GETNICK -9
#define LINK_ERROR_GETOPNICK -10
#define LINK_ERROR_GAMEOVER -11
#define LINK_ERROR_INGAME -12
#define LINK_ERROR_CLEAR -13
#define LINK_ERROR_GETINFO -14
#define LINK_ERROR_GETAVERANK -15
#define LINK_ERROR_RESET -16
#define LINK_ERROR_GETWINRANK -17
#define LINK_ERROR_GETHIGHRANK -18
void Webread(void *cxt);
void WebAction_Status(void *p, WebStatus ws, void *pVal);
class CNetwork
{
public:
CNetwork(CEngine *p);
~CNetwork();
int Login();
int getNickName(char *);//return 0: connecting; -1: connect error; 1: get response, stores nick name in string, NULL for no nick name
int setNickName(char *);//return 0: connecting; 1: nickname accepted; -2: nickname already took; -1: error
int getRivalName(char *name, int *highscore=NULL, int *winrank=NULL, int *averank=NULL);//return 0: connecting; 1: receive rival name; -1: error
int wantChallenge(bool chal, int *state);//return 0: connecting; -1: error; 1: receive response, state:1,start game; state:0,cancel game
int sendMyScore(int *myscore);//return 0: connecting; -1: error; 1: send succeed
int receiveOpPinMode(int *OpPinMode);//return 0: connecting; -1: error; 1: receive succeed
int getGameResult();//return 0: connecting; -1: error; 1: receive succeed
int resetProfile();//return 0: connecting; -1: error; 1: receive succeed
int getUserInfo(int *win, int *loss, int *draw, int *highscore, int *winrank, int *averank=NULL);//return 0: connecting; -1: error; 1: get result
void InvalidInfo(){bValidInfo=false;statusOfOnline = WEB_STATE_NONE;}
int getAveRank(RANK_DATA*);
void InvalidAveRank(){bAveRankValid=false;statusOfOnline = WEB_STATE_NONE;}
int getWinRank(RANK_DATA*);
void InvalidWinRank(){bWinRankValid=false;statusOfOnline = WEB_STATE_NONE;}
int getRank(RANK_DATA *p);
void InvalidRank(){bHighRankValid=false;statusOfOnline = WEB_STATE_NONE;}
int keepConnect();//return 0: connecting; -1: error; 1: connected
void stopConnect();
int InitConnect();
void makeUrl();
bool generateUser();
char score[21];//remember the score .
int statusOfOnline;
int statusOfLink;
int statusOfWeb;
bool bChallenge;// accept or make a challenge with others
char webStatus[50];
char url[150]; // the url for quarry
char allurl[250]; // the full url
char result[250];
int resultSize;
bool resultOK;// the return body is ok
char returnInfo[2][120];
char returnVal[120];
char originURL[100];
private:
CEngine * m_pEngine; // point to GAme Engine
bool bnickName; // if the user have the correct nickname,will be saved
bool buserID;
int m_onlinePlayerPinStatus[3]; //yjf 2004-12-20 for interactive // del by YChen 16/2/2005 for del interactive mode
bool blogin;
// most important : these character arrays must be init as the string.
char nickName[10];
char userID[20];
char gameID[80];
char nextSEQ[10];
RANK_DATA pHighRank[MAX_RANK_NUM];
bool bHighRankValid;
RANK_DATA pAveRank[MAX_RANK_NUM];
bool bAveRankValid;
RANK_DATA pWinRank[MAX_RANK_NUM];
bool bWinRankValid;
bool bOpScoreValid;
bool bOpponent;// if be opponent by others
bool bWopponent;// if want to opponent
char OpuserID[21];//Opponent name and userid
char OpnickName[10];
int OpHighscore;
int OpAveRank;
int OpWinRank;
int challengeState;//1: start game; 2: reject
int scoreState;//1: need send; 2: wait rival score; 3: get rival score
bool connecterror; //in game
int current_turn;
char data[4];
int connecttime;
bool bgetGameResult;
//game result
bool bValidInfo;
int m_Win;
int m_Loss;
int m_Draw;
int m_highScore;
int m_winRank;
int m_aveRank;
int parseResult();
bool OpenUrl();
void OnlineUpdate();
void makeConnect();
void processReceiveData();
bool getUrl(char *pUrl);
int errorcode;
bool m_bTimeOut;
bool m_buseTick;
void startTick( int outTime);
bool checkTick();
void clearTick();
inline void setUseTick()
{
m_buseTick = true;
}
inline void clearUseTick()
{
m_buseTick = false;
}
inline bool getUseTick()
{
return m_buseTick;
}
int m_nTickTime;
int m_nOutTime;
int m_nErrorType;
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -