2
3
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-14 02:27:40 -04:00

Initial Commit of CyanWorlds.com Engine Open Source Client/Plugin

This commit is contained in:
JWPlatt
2011-03-12 12:34:52 -05:00
commit a20a222fc2
3976 changed files with 1301356 additions and 0 deletions

View File

@ -0,0 +1,269 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/FeatureLib/pfGameMgr/BlueSpiral/pfGmBlueSpiral.cpp
*
***/
#define USES_GAME_BLUESPIRAL
#include "../Pch.h"
#pragma hdrstop
/*****************************************************************************
*
* Local types
*
***/
struct IBlueSpiral {
pfGmBlueSpiral * gameCli;
IBlueSpiral (pfGmBlueSpiral * gameCli);
// pfGameCli event notification handlers
void Recv (GameMsgHeader * msg, void * param);
void OnPlayerJoined (const Srv2Cli_Game_PlayerJoined & msg);
void OnPlayerLeft (const Srv2Cli_Game_PlayerLeft & msg);
void OnInviteFailed (const Srv2Cli_Game_InviteFailed & msg);
void OnOwnerChange (const Srv2Cli_Game_OwnerChange & msg);
// BlueSpiral network message handlers
void RecvClothOrder (const Srv2Cli_BlueSpiral_ClothOrder & msg, void * param);
void RecvSuccessfulHit (const Srv2Cli_BlueSpiral_SuccessfulHit & msg, void * param);
void RecvGameWon (const Srv2Cli_BlueSpiral_GameWon & msg, void * param);
void RecvGameOver (const Srv2Cli_BlueSpiral_GameOver & msg, void * param);
void RecvGameStarted (const Srv2Cli_BlueSpiral_GameStarted & msg, void * param);
};
/*****************************************************************************
*
* Factory functions
*
***/
//============================================================================
static pfGameCli * BlueSpiralFactory (
unsigned gameId,
plKey receiver
) {
return NEWZERO(pfGmBlueSpiral)(gameId, receiver);
}
//============================================================================
AUTO_INIT_FUNC(RegisterBlueSpiralFactory) {
static GameTypeReg reg = {
BlueSpiralFactory,
kGameTypeId_BlueSpiral,
L"BlueSpiral"
};
GameMgrRegisterGameType(reg);
}
/*****************************************************************************
*
* IBlueSpiral
*
***/
//============================================================================
IBlueSpiral::IBlueSpiral (pfGmBlueSpiral * gameCli)
: gameCli(gameCli)
{
}
//============================================================================
void IBlueSpiral::OnPlayerJoined (const Srv2Cli_Game_PlayerJoined & msg) {
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IBlueSpiral::OnPlayerLeft (const Srv2Cli_Game_PlayerLeft & msg) {
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IBlueSpiral::OnInviteFailed (const Srv2Cli_Game_InviteFailed & msg) {
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IBlueSpiral::OnOwnerChange (const Srv2Cli_Game_OwnerChange & msg) {
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IBlueSpiral::RecvClothOrder (const Srv2Cli_BlueSpiral_ClothOrder & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IBlueSpiral::RecvSuccessfulHit (const Srv2Cli_BlueSpiral_SuccessfulHit & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IBlueSpiral::RecvGameWon (const Srv2Cli_BlueSpiral_GameWon & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IBlueSpiral::RecvGameOver (const Srv2Cli_BlueSpiral_GameOver & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IBlueSpiral::RecvGameStarted (const Srv2Cli_BlueSpiral_GameStarted & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
/*****************************************************************************
*
* pfGmBlueSpiral
*
***/
//============================================================================
pfGmBlueSpiral::pfGmBlueSpiral (
unsigned gameId,
plKey receiver
)
: pfGameCli(gameId, receiver)
{
internal = NEWZERO(IBlueSpiral)(this);
}
//============================================================================
pfGmBlueSpiral::~pfGmBlueSpiral () {
DEL(internal);
}
//============================================================================
void pfGmBlueSpiral::Recv (GameMsgHeader * msg, void * param) {
#define DISPATCH(a) case kSrv2Cli_BlueSpiral_##a: { \
const Srv2Cli_BlueSpiral_##a & m = *(const Srv2Cli_BlueSpiral_##a *)msg; \
internal->Recv##a(m, param); \
} \
break; //
switch (msg->messageId) {
DISPATCH(ClothOrder);
DISPATCH(SuccessfulHit);
DISPATCH(GameWon);
DISPATCH(GameOver);
DISPATCH(GameStarted);
DEFAULT_FATAL(msg->messageId);
}
#undef DISPATCH
}
//============================================================================
void pfGmBlueSpiral::OnPlayerJoined (const Srv2Cli_Game_PlayerJoined & msg) {
internal->OnPlayerJoined(msg);
}
//============================================================================
void pfGmBlueSpiral::OnPlayerLeft (const Srv2Cli_Game_PlayerLeft & msg) {
internal->OnPlayerLeft(msg);
}
//============================================================================
void pfGmBlueSpiral::OnInviteFailed (const Srv2Cli_Game_InviteFailed & msg) {
internal->OnInviteFailed(msg);
}
//============================================================================
void pfGmBlueSpiral::OnOwnerChange (const Srv2Cli_Game_OwnerChange & msg) {
internal->OnOwnerChange(msg);
}
//============================================================================
void pfGmBlueSpiral::StartGame () {
Cli2Srv_BlueSpiral_StartGame msg;
msg.messageId = kCli2Srv_BlueSpiral_StartGame;
msg.messageBytes = sizeof(msg);
msg.recvGameId = GetGameId(); // send to GameSrv on server
msg.transId = 0;
GameMgrSend(&msg);
}
//============================================================================
void pfGmBlueSpiral::HitCloth (int clothNum) {
Cli2Srv_BlueSpiral_HitCloth msg;
msg.messageId = kCli2Srv_BlueSpiral_HitCloth;
msg.messageBytes = sizeof(msg);
msg.recvGameId = GetGameId(); // send to GameSrv on server
msg.transId = 0;
msg.clothNum = clothNum;
GameMgrSend(&msg);
}

View File

@ -0,0 +1,77 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/FeatureLib/pfGameMgr/TicTacToe/pfGmTicTacToe.h
*
***/
#ifdef PLASMA20_SOURCES_PLASMA_FEATURELIB_PFGAMEMGR_BLUESPIRAL_PFGMBLUESPIRAL_H
#error "Header $/Plasma20/Sources/Plasma/FeatureLib/pfGameMgr/BlueSpiral/pfGmBlueSpiral.h included more than once"
#endif
#define PLASMA20_SOURCES_PLASMA_FEATURELIB_PFGAMEMGR_BLUESPIRAL_PFGMBLUESPIRAL_H
/*****************************************************************************
*
* pfGmBlueSpiral interface
*
***/
class pfGmBlueSpiral : public pfGameCli {
// Encapsulate all implementation details such as member fields
// in an opaque friend class, in this case that's IBlueSpiral.
friend struct IBlueSpiral;
struct IBlueSpiral * internal;
//========================================================================
// Required subclass methods
//--------------------------
void Recv (GameMsgHeader * msg, void * param);
void OnPlayerJoined (const Srv2Cli_Game_PlayerJoined & msg);
void OnPlayerLeft (const Srv2Cli_Game_PlayerLeft & msg);
void OnInviteFailed (const Srv2Cli_Game_InviteFailed & msg);
void OnOwnerChange (const Srv2Cli_Game_OwnerChange & msg);
//========================================================================
public:
#pragma warning(push, 0)
// These macros produce warnings on W4
CLASSNAME_REGISTER(pfGmBlueSpiral);
GETINTERFACE_ANY(pfGmBlueSpiral, pfGameCli);
#pragma warning(pop)
pfGmBlueSpiral (unsigned gameId, plKey receiver);
~pfGmBlueSpiral ();
//========================================================================
// Game methods
//-------------
void StartGame ();
void HitCloth (int clothNum);
//========================================================================
};

View File

@ -0,0 +1,346 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/FeatureLib/pfGameMgr/ClimbingWall/pfGmClimbingWall.cpp
*
***/
#define USES_GAME_CLIMBINGWALL
#include "../Pch.h"
#pragma hdrstop
/*****************************************************************************
*
* Local types
*
***/
struct IClimbingWall {
pfGmClimbingWall * gameCli;
IClimbingWall (pfGmClimbingWall * gameCli);
// pfGameCli event notification handlers
void Recv (GameMsgHeader * msg, void * param);
void OnPlayerJoined (const Srv2Cli_Game_PlayerJoined & msg);
void OnPlayerLeft (const Srv2Cli_Game_PlayerLeft & msg);
void OnInviteFailed (const Srv2Cli_Game_InviteFailed & msg);
void OnOwnerChange (const Srv2Cli_Game_OwnerChange & msg);
// ClimbingWall network message handlers
void RecvNumBlockersChanged (const Srv2Cli_ClimbingWall_NumBlockersChanged & msg, void * param);
void RecvReady (const Srv2Cli_ClimbingWall_Ready & msg, void * param);
void RecvBlockersChanged (const Srv2Cli_ClimbingWall_BlockersChanged & msg, void * param);
void RecvPlayerEntered (const Srv2Cli_ClimbingWall_PlayerEntered & msg, void * param);
void RecvSuitMachineLocked (const Srv2Cli_ClimbingWall_SuitMachineLocked & msg, void * param);
void RecvGameOver (const Srv2Cli_ClimbingWall_GameOver & msg, void * param);
};
/*****************************************************************************
*
* Factory functions
*
***/
//============================================================================
static pfGameCli * ClimbingWallFactory (
unsigned gameId,
plKey receiver
) {
return NEWZERO(pfGmClimbingWall)(gameId, receiver);
}
//============================================================================
AUTO_INIT_FUNC(RegisterClimbingWallFactory) {
static GameTypeReg reg = {
ClimbingWallFactory,
kGameTypeId_ClimbingWall,
L"ClimbingWall"
};
GameMgrRegisterGameType(reg);
}
/*****************************************************************************
*
* IClimbingWall
*
***/
//============================================================================
IClimbingWall::IClimbingWall (pfGmClimbingWall * gameCli)
: gameCli(gameCli)
{
}
//============================================================================
void IClimbingWall::OnPlayerJoined (const Srv2Cli_Game_PlayerJoined & msg) {
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IClimbingWall::OnPlayerLeft (const Srv2Cli_Game_PlayerLeft & msg) {
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IClimbingWall::OnInviteFailed (const Srv2Cli_Game_InviteFailed & msg) {
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IClimbingWall::OnOwnerChange (const Srv2Cli_Game_OwnerChange & msg) {
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IClimbingWall::RecvNumBlockersChanged (const Srv2Cli_ClimbingWall_NumBlockersChanged & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IClimbingWall::RecvReady (const Srv2Cli_ClimbingWall_Ready & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IClimbingWall::RecvBlockersChanged (const Srv2Cli_ClimbingWall_BlockersChanged & msg, void * param) {
ref (param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IClimbingWall::RecvPlayerEntered (const Srv2Cli_ClimbingWall_PlayerEntered & msg, void * param) {
ref (param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IClimbingWall::RecvSuitMachineLocked (const Srv2Cli_ClimbingWall_SuitMachineLocked & msg, void * param) {
ref (param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IClimbingWall::RecvGameOver (const Srv2Cli_ClimbingWall_GameOver & msg, void * param) {
ref (param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
/*****************************************************************************
*
* pfGmClimbingWall
*
***/
//============================================================================
pfGmClimbingWall::pfGmClimbingWall (
unsigned gameId,
plKey receiver
)
: pfGameCli(gameId, receiver)
{
internal = NEWZERO(IClimbingWall)(this);
}
//============================================================================
pfGmClimbingWall::~pfGmClimbingWall () {
DEL(internal);
}
//============================================================================
void pfGmClimbingWall::Recv (GameMsgHeader * msg, void * param) {
#define DISPATCH(a) case kSrv2Cli_ClimbingWall_##a: { \
const Srv2Cli_ClimbingWall_##a & m = *(const Srv2Cli_ClimbingWall_##a *)msg; \
internal->Recv##a(m, param); \
} \
break; //
switch (msg->messageId) {
DISPATCH(NumBlockersChanged);
DISPATCH(Ready);
DISPATCH(BlockersChanged);
DISPATCH(PlayerEntered);
DISPATCH(SuitMachineLocked);
DISPATCH(GameOver);
DEFAULT_FATAL(msg->messageId);
}
#undef DISPATCH
}
//============================================================================
void pfGmClimbingWall::OnPlayerJoined (const Srv2Cli_Game_PlayerJoined & msg) {
internal->OnPlayerJoined(msg);
}
//============================================================================
void pfGmClimbingWall::OnPlayerLeft (const Srv2Cli_Game_PlayerLeft & msg) {
internal->OnPlayerLeft(msg);
}
//============================================================================
void pfGmClimbingWall::OnInviteFailed (const Srv2Cli_Game_InviteFailed & msg) {
internal->OnInviteFailed(msg);
}
//============================================================================
void pfGmClimbingWall::OnOwnerChange (const Srv2Cli_Game_OwnerChange & msg) {
internal->OnOwnerChange(msg);
}
//============================================================================
void pfGmClimbingWall::ChangeNumBlockers (int amountToAdjust) {
Cli2Srv_ClimbingWall_ChangeNumBlockers msg;
msg.messageId = kCli2Srv_ClimbingWall_ChangeNumBlockers;
msg.messageBytes = sizeof(msg);
msg.recvGameId = GetGameId(); // send to GameSrv on server
msg.transId = 0;
msg.amountToAdjust = amountToAdjust;
GameMgrSend(&msg);
}
//============================================================================
void pfGmClimbingWall::Ready (unsigned readyType, unsigned teamNumber) {
Cli2Srv_ClimbingWall_Ready msg;
msg.messageId = kCli2Srv_ClimbingWall_Ready;
msg.messageBytes = sizeof(msg);
msg.recvGameId = GetGameId(); // send to GameSrv on server
msg.transId = 0;
msg.readyType = (byte)readyType;
msg.teamNumber = (byte)teamNumber;
GameMgrSend(&msg);
}
//============================================================================
void pfGmClimbingWall::ChangeBlocker (unsigned teamNumber, unsigned blockerNumber, bool added) {
Cli2Srv_ClimbingWall_BlockerChanged msg;
msg.messageId = kCli2Srv_ClimbingWall_BlockerChanged;
msg.messageBytes = sizeof(msg);
msg.recvGameId = GetGameId(); // send to GameSrv on server
msg.transId = 0;
msg.teamNumber = (byte)teamNumber;
msg.blockerNumber = (byte)blockerNumber;
msg.added = added;
GameMgrSend(&msg);
}
//============================================================================
void pfGmClimbingWall::Reset () {
Cli2Srv_ClimbingWall_Reset msg;
msg.messageId = kCli2Srv_ClimbingWall_Reset;
msg.messageBytes = sizeof(msg);
msg.recvGameId = GetGameId(); // send to GameSrv on server
msg.transId = 0;
GameMgrSend(&msg);
}
//============================================================================
void pfGmClimbingWall::PlayerEntered (unsigned teamNumber) {
Cli2Srv_ClimbingWall_PlayerEntered msg;
msg.messageId = kCli2Srv_ClimbingWall_PlayerEntered;
msg.messageBytes = sizeof(msg);
msg.recvGameId = GetGameId(); // send to GameSrv on server
msg.transId = 0;
msg.teamNumber = (byte)teamNumber;
GameMgrSend(&msg);
}
//============================================================================
void pfGmClimbingWall::FinishedGame () {
Cli2Srv_ClimbingWall_FinishedGame msg;
msg.messageId = kCli2Srv_ClimbingWall_FinishedGame;
msg.messageBytes = sizeof(msg);
msg.recvGameId = GetGameId(); // send to GameSrv on server
msg.transId = 0;
GameMgrSend(&msg);
}
//============================================================================
void pfGmClimbingWall::Panic () {
Cli2Srv_ClimbingWall_Panic msg;
msg.messageId = kCli2Srv_ClimbingWall_Panic;
msg.messageBytes = sizeof(msg);
msg.recvGameId = GetGameId(); // send to GameSrv on server
msg.transId = 0;
GameMgrSend(&msg);
}

View File

@ -0,0 +1,82 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/FeatureLib/pfGameMgr/ClimbingWall/pfGmClimbingWall.h
*
***/
#ifdef PLASMA20_SOURCES_PLASMA_FEATURELIB_PFGAMEMGR_CLIMBINGWALL_PFGMCLIMBINGWALL_H
#error "Header $/Plasma20/Sources/Plasma/FeatureLib/pfGameMgr/ClimbingWall/pfGmClimbingWall.h included more than once"
#endif
#define PLASMA20_SOURCES_PLASMA_FEATURELIB_PFGAMEMGR_CLIMBINGWALL_PFGMCLIMBINGWALL_H
/*****************************************************************************
*
* pfGmClimbingWall interface
*
***/
class pfGmClimbingWall : public pfGameCli {
// Encapsulate all implementation details such as member fields
// in an opaque friend class, in this case that's IClimbingWall.
friend struct IClimbingWall;
struct IClimbingWall * internal;
//========================================================================
// Required subclass methods
//--------------------------
void Recv (GameMsgHeader * msg, void * param);
void OnPlayerJoined (const Srv2Cli_Game_PlayerJoined & msg);
void OnPlayerLeft (const Srv2Cli_Game_PlayerLeft & msg);
void OnInviteFailed (const Srv2Cli_Game_InviteFailed & msg);
void OnOwnerChange (const Srv2Cli_Game_OwnerChange & msg);
//========================================================================
public:
#pragma warning(push, 0)
// These macros produce warnings on W4
CLASSNAME_REGISTER(pfGmClimbingWall);
GETINTERFACE_ANY(pfGmClimbingWall, pfGameCli);
#pragma warning(pop)
pfGmClimbingWall (unsigned gameId, plKey receiver);
~pfGmClimbingWall ();
//========================================================================
// Game methods
//-------------
void ChangeNumBlockers (int amountToAdjust);
void Ready (unsigned readyType, unsigned teamNumber);
void ChangeBlocker (unsigned teamNumber, unsigned blockerNumber, bool added);
void Reset ();
void PlayerEntered (unsigned teamNumber);
void FinishedGame ();
void Panic ();
//========================================================================
};

View File

@ -0,0 +1,341 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/FeatureLib/pfGameMgr/TicTacToe/pfGmTicTacToe.cpp
*
***/
#define USES_GAME_HEEK
#include "../Pch.h"
#pragma hdrstop
/*****************************************************************************
*
* Local types
*
***/
struct IHeek {
pfGmHeek * gameCli;
IHeek (pfGmHeek * gameCli);
// pfGameCli event notification handlers
void Recv (GameMsgHeader * msg, void * param);
void OnPlayerJoined (const Srv2Cli_Game_PlayerJoined & msg);
void OnPlayerLeft (const Srv2Cli_Game_PlayerLeft & msg);
void OnInviteFailed (const Srv2Cli_Game_InviteFailed & msg);
void OnOwnerChange (const Srv2Cli_Game_OwnerChange & msg);
// Heek network message handlers
void RecvPlayGame (const Srv2Cli_Heek_PlayGame & msg, void * param);
void RecvGoodbye (const Srv2Cli_Heek_Goodbye & msg, void * param);
void RecvWelcome (const Srv2Cli_Heek_Welcome & msg, void * param);
void RecvDrop (const Srv2Cli_Heek_Drop & msg, void * param);
void RecvSetup (const Srv2Cli_Heek_Setup & msg, void * param);
void RecvLightState (const Srv2Cli_Heek_LightState & msg, void * param);
void RecvInterfaceState (const Srv2Cli_Heek_InterfaceState & msg, void * param);
void RecvCountdownState (const Srv2Cli_Heek_CountdownState & msg, void * param);
void RecvWinLose (const Srv2Cli_Heek_WinLose & msg, void * param);
void RecvGameWin (const Srv2Cli_Heek_GameWin & msg, void * param);
void RecvPointUpdate (const Srv2Cli_Heek_PointUpdate & msg, void * param);
};
/*****************************************************************************
*
* Factory functions
*
***/
//============================================================================
static pfGameCli * HeekFactory (
unsigned gameId,
plKey receiver
) {
return NEWZERO(pfGmHeek)(gameId, receiver);
}
//============================================================================
AUTO_INIT_FUNC(RegisterHeek) {
static GameTypeReg reg = {
HeekFactory,
kGameTypeId_Heek,
L"Heek"
};
GameMgrRegisterGameType(reg);
}
/*****************************************************************************
*
* IHeek
*
***/
//============================================================================
IHeek::IHeek (pfGmHeek * gameCli)
: gameCli(gameCli)
{
}
//============================================================================
void IHeek::OnPlayerJoined (const Srv2Cli_Game_PlayerJoined & msg) {
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IHeek::OnPlayerLeft (const Srv2Cli_Game_PlayerLeft & msg) {
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IHeek::OnInviteFailed (const Srv2Cli_Game_InviteFailed & msg) {
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IHeek::OnOwnerChange (const Srv2Cli_Game_OwnerChange & msg) {
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IHeek::RecvPlayGame (const Srv2Cli_Heek_PlayGame & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IHeek::RecvGoodbye (const Srv2Cli_Heek_Goodbye & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IHeek::RecvWelcome (const Srv2Cli_Heek_Welcome & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IHeek::RecvDrop (const Srv2Cli_Heek_Drop & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IHeek::RecvSetup (const Srv2Cli_Heek_Setup & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IHeek::RecvLightState (const Srv2Cli_Heek_LightState & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IHeek::RecvInterfaceState (const Srv2Cli_Heek_InterfaceState & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IHeek::RecvCountdownState (const Srv2Cli_Heek_CountdownState & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IHeek::RecvWinLose (const Srv2Cli_Heek_WinLose & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IHeek::RecvGameWin (const Srv2Cli_Heek_GameWin & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IHeek::RecvPointUpdate (const Srv2Cli_Heek_PointUpdate & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
/*****************************************************************************
*
* pfGmHeek
*
***/
//============================================================================
pfGmHeek::pfGmHeek (
unsigned gameId,
plKey receiver
)
: pfGameCli(gameId, receiver)
{
internal = NEWZERO(IHeek)(this);
}
//============================================================================
pfGmHeek::~pfGmHeek () {
DEL(internal);
}
//============================================================================
void pfGmHeek::Recv (GameMsgHeader * msg, void * param) {
#define DISPATCH(a) case kSrv2Cli_Heek_##a: { \
const Srv2Cli_Heek_##a & m = *(const Srv2Cli_Heek_##a *)msg; \
internal->Recv##a(m, param); \
} \
break;
switch (msg->messageId) {
DISPATCH(PlayGame);
DISPATCH(Goodbye);
DISPATCH(Welcome);
DISPATCH(Drop);
DISPATCH(Setup);
DISPATCH(LightState);
DISPATCH(InterfaceState);
DISPATCH(CountdownState);
DISPATCH(WinLose);
DISPATCH(GameWin);
DISPATCH(PointUpdate);
DEFAULT_FATAL(msg->messageId);
}
#undef DISPATCH
}
//============================================================================
void pfGmHeek::OnPlayerJoined (const Srv2Cli_Game_PlayerJoined & msg) {
internal->OnPlayerJoined(msg);
}
//============================================================================
void pfGmHeek::OnPlayerLeft (const Srv2Cli_Game_PlayerLeft & msg) {
internal->OnPlayerLeft(msg);
}
//============================================================================
void pfGmHeek::OnInviteFailed (const Srv2Cli_Game_InviteFailed & msg) {
internal->OnInviteFailed(msg);
}
//============================================================================
void pfGmHeek::OnOwnerChange (const Srv2Cli_Game_OwnerChange & msg) {
internal->OnOwnerChange(msg);
}
//============================================================================
void pfGmHeek::PlayGame (unsigned position, dword points, const wchar name[]) {
Cli2Srv_Heek_PlayGame msg;
msg.messageId = kCli2Srv_Heek_PlayGame;
msg.messageBytes = sizeof(msg);
msg.recvGameId = GetGameId(); // send to GameSrv on server
msg.transId = 0;
msg.position = (byte)position;
msg.points = points;
StrCopy(msg.name, name, arrsize(msg.name));
GameMgrSend(&msg);
}
//============================================================================
void pfGmHeek::LeaveGame () {
Cli2Srv_Heek_LeaveGame msg;
msg.messageId = kCli2Srv_Heek_LeaveGame;
msg.messageBytes = sizeof(msg);
msg.recvGameId = GetGameId(); // send to GameSrv on server
msg.transId = 0;
GameMgrSend(&msg);
}
//============================================================================
void pfGmHeek::Choose (EHeekChoice choice) {
Cli2Srv_Heek_Choose msg;
msg.messageId = kCli2Srv_Heek_Choose;
msg.messageBytes = sizeof(msg);
msg.recvGameId = GetGameId(); // send to GameSrv on server
msg.transId = 0;
msg.choice = (byte)choice;
GameMgrSend(&msg);
}
//============================================================================
void pfGmHeek::SequenceFinished (EHeekSeqFinished seq) {
Cli2Srv_Heek_SeqFinished msg;
msg.messageId = kCli2Srv_Heek_SeqFinished;
msg.messageBytes = sizeof(msg);
msg.recvGameId = GetGameId(); // send to GameSrv on server
msg.transId = 0;
msg.seqFinished = (byte)seq;
GameMgrSend(&msg);
}

View File

@ -0,0 +1,78 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/FeatureLib/pfGameMgr/Heek/pfGmHeek.h
*
***/
#ifdef PLASMA20_SOURCES_PLASMA_FEATURELIB_PFGAMEMGR_HEEK_PFGMHEEK_H
#error "Header $/Plasma20/Sources/Plasma/FeatureLib/pfGameMgr/Heek/pfGmHeek.h included more than once"
#endif
#define PLASMA20_SOURCES_PLASMA_FEATURELIB_PFGAMEMGR_HEEK_PFGMHEEK_H
/*****************************************************************************
*
* pfGmHeek interface
*
***/
class pfGmHeek : public pfGameCli {
// Encapsulate all implementation details such as member fields
// in an opaque friend class, in this case that's IHeek.
friend struct IHeek;
struct IHeek * internal;
//========================================================================
// Required subclass methods
//--------------------------
void Recv (GameMsgHeader * msg, void * param);
void OnPlayerJoined (const Srv2Cli_Game_PlayerJoined & msg);
void OnPlayerLeft (const Srv2Cli_Game_PlayerLeft & msg);
void OnInviteFailed (const Srv2Cli_Game_InviteFailed & msg);
void OnOwnerChange (const Srv2Cli_Game_OwnerChange & msg);
//========================================================================
public:
#pragma warning(push, 0)
// These macros produce warnings on W4
CLASSNAME_REGISTER(pfGmHeek);
GETINTERFACE_ANY(pfGmHeek, pfGameCli);
#pragma warning(pop)
pfGmHeek (unsigned gameId, plKey receiver);
~pfGmHeek ();
//========================================================================
// Game methods
//-------------
void PlayGame (unsigned position, dword points, const wchar name[]);
void LeaveGame ();
void Choose (EHeekChoice choice);
void SequenceFinished (EHeekSeqFinished seq);
//========================================================================
};

View File

@ -0,0 +1,57 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/FeatureLib/pfGameMgr/Intern.h
*
***/
#ifdef PLASMA20_SOURCES_PLASMA_FEATURELIB_PFGAMEMGR_INTERN_H
#error "Header $/Plasma20/Sources/Plasma/FeatureLib/pfGameMgr/Intern.h included more than once"
#endif
#define PLASMA20_SOURCES_PLASMA_FEATURELIB_PFGAMEMGR_INTERN_H
/*****************************************************************************
*
* GameMgr
*
***/
typedef pfGameCli * (*FGameCliFactory)(
unsigned gameSrvId,
plKey receiver
);
struct GameTypeReg {
FGameCliFactory create;
Uuid typeId;
const wchar * name;
};
void GameMgrRegisterGameType (const GameTypeReg & reg);
void GameMgrSend (GameMsgHeader * msg, void * param = nil);

View File

@ -0,0 +1,475 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/FeatureLib/pfGameMgr/TicTacToe/pfGmTicTacToe.cpp
*
***/
#define USES_GAME_MARKER
#include "../Pch.h"
#pragma hdrstop
/*****************************************************************************
*
* Local types
*
***/
struct IMarker {
pfGmMarker * gameCli;
IMarker (pfGmMarker * gameCli);
// pfGameCli event notification handlers
void Recv (GameMsgHeader * msg, void * param);
void OnPlayerJoined (const Srv2Cli_Game_PlayerJoined & msg);
void OnPlayerLeft (const Srv2Cli_Game_PlayerLeft & msg);
void OnInviteFailed (const Srv2Cli_Game_InviteFailed & msg);
void OnOwnerChange (const Srv2Cli_Game_OwnerChange & msg);
// Marker network message handlers
void RecvTemplateCreated (const Srv2Cli_Marker_TemplateCreated & msg, void * param);
void RecvTeamAssigned (const Srv2Cli_Marker_TeamAssigned & msg, void * param);
void RecvGameType (const Srv2Cli_Marker_GameType & msg, void * param);
void RecvGameStarted (const Srv2Cli_Marker_GameStarted & msg, void * param);
void RecvGamePaused (const Srv2Cli_Marker_GamePaused & msg, void * param);
void RecvGameReset (const Srv2Cli_Marker_GameReset & msg, void * param);
void RecvGameOver (const Srv2Cli_Marker_GameOver & msg, void * param);
void RecvGameNameChanged (const Srv2Cli_Marker_GameNameChanged & msg, void * param);
void RecvTimeLimitChanged (const Srv2Cli_Marker_TimeLimitChanged & msg, void * param);
void RecvGameDeleted (const Srv2Cli_Marker_GameDeleted & msg, void * param);
void RecvMarkerAdded (const Srv2Cli_Marker_MarkerAdded & msg, void * param);
void RecvMarkerDeleted (const Srv2Cli_Marker_MarkerDeleted & msg, void * param);
void RecvMarkerNameChanged (const Srv2Cli_Marker_MarkerNameChanged & msg, void * param);
void RecvMarkerCaptured (const Srv2Cli_Marker_MarkerCaptured & msg, void * param);
};
/*****************************************************************************
*
* Factory functions
*
***/
//============================================================================
static pfGameCli * MarkerFactory (
unsigned gameId,
plKey receiver
) {
return NEWZERO(pfGmMarker)(gameId, receiver);
}
//============================================================================
AUTO_INIT_FUNC(RegisterMarkerFactory) {
static GameTypeReg reg = {
MarkerFactory,
kGameTypeId_Marker,
L"Marker"
};
GameMgrRegisterGameType(reg);
}
/*****************************************************************************
*
* IMarker
*
***/
//============================================================================
IMarker::IMarker (pfGmMarker * gameCli)
: gameCli(gameCli)
{
}
//============================================================================
void IMarker::OnPlayerJoined (const Srv2Cli_Game_PlayerJoined & msg) {
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IMarker::OnPlayerLeft (const Srv2Cli_Game_PlayerLeft & msg) {
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IMarker::OnInviteFailed (const Srv2Cli_Game_InviteFailed & msg) {
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IMarker::OnOwnerChange (const Srv2Cli_Game_OwnerChange & msg) {
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IMarker::RecvTemplateCreated (const Srv2Cli_Marker_TemplateCreated & msg, void * param) {
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IMarker::RecvTeamAssigned (const Srv2Cli_Marker_TeamAssigned & msg, void * param) {
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IMarker::RecvGameType (const Srv2Cli_Marker_GameType & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IMarker::RecvGameStarted (const Srv2Cli_Marker_GameStarted & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IMarker::RecvGamePaused (const Srv2Cli_Marker_GamePaused & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IMarker::RecvGameReset (const Srv2Cli_Marker_GameReset & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IMarker::RecvGameOver (const Srv2Cli_Marker_GameOver & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IMarker::RecvGameNameChanged (const Srv2Cli_Marker_GameNameChanged & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IMarker::RecvTimeLimitChanged (const Srv2Cli_Marker_TimeLimitChanged & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IMarker::RecvGameDeleted (const Srv2Cli_Marker_GameDeleted & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
if (!msg.failed)
DEL(gameCli); // we're done
}
//============================================================================
void IMarker::RecvMarkerAdded (const Srv2Cli_Marker_MarkerAdded & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IMarker::RecvMarkerDeleted (const Srv2Cli_Marker_MarkerDeleted & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IMarker::RecvMarkerNameChanged (const Srv2Cli_Marker_MarkerNameChanged & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IMarker::RecvMarkerCaptured (const Srv2Cli_Marker_MarkerCaptured & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
/*****************************************************************************
*
* pfGmMarker
*
***/
//============================================================================
pfGmMarker::pfGmMarker (
unsigned gameId,
plKey receiver
)
: pfGameCli(gameId, receiver)
{
internal = NEWZERO(IMarker)(this);
}
//============================================================================
pfGmMarker::~pfGmMarker () {
DEL(internal);
}
//============================================================================
void pfGmMarker::Recv (GameMsgHeader * msg, void * param) {
#define DISPATCH(a) case kSrv2Cli_Marker_##a: { \
const Srv2Cli_Marker_##a & m = *(const Srv2Cli_Marker_##a *)msg; \
internal->Recv##a(m, param); \
} \
break; //
switch (msg->messageId) {
DISPATCH(TemplateCreated);
DISPATCH(TeamAssigned);
DISPATCH(GameType);
DISPATCH(GameStarted);
DISPATCH(GamePaused);
DISPATCH(GameReset);
DISPATCH(GameOver);
DISPATCH(GameNameChanged);
DISPATCH(TimeLimitChanged);
DISPATCH(GameDeleted);
DISPATCH(MarkerAdded);
DISPATCH(MarkerDeleted);
DISPATCH(MarkerNameChanged);
DISPATCH(MarkerCaptured);
DEFAULT_FATAL(msg->messageId);
}
#undef DISPATCH
}
//============================================================================
void pfGmMarker::OnPlayerJoined (const Srv2Cli_Game_PlayerJoined & msg) {
internal->OnPlayerJoined(msg);
}
//============================================================================
void pfGmMarker::OnPlayerLeft (const Srv2Cli_Game_PlayerLeft & msg) {
internal->OnPlayerLeft(msg);
}
//============================================================================
void pfGmMarker::OnInviteFailed (const Srv2Cli_Game_InviteFailed & msg) {
internal->OnInviteFailed(msg);
}
//============================================================================
void pfGmMarker::OnOwnerChange (const Srv2Cli_Game_OwnerChange & msg) {
internal->OnOwnerChange(msg);
}
//============================================================================
void pfGmMarker::StartGame () {
Cli2Srv_Marker_StartGame msg;
msg.messageId = kCli2Srv_Marker_StartGame;
msg.messageBytes = sizeof(msg);
msg.recvGameId = GetGameId(); // send to GameSrv on server
msg.transId = 0;
GameMgrSend(&msg);
}
//============================================================================
void pfGmMarker::PauseGame () {
Cli2Srv_Marker_StartGame msg;
msg.messageId = kCli2Srv_Marker_PauseGame;
msg.messageBytes = sizeof(msg);
msg.recvGameId = GetGameId(); // send to GameSrv on server
msg.transId = 0;
GameMgrSend(&msg);
}
//============================================================================
void pfGmMarker::ResetGame () {
Cli2Srv_Marker_StartGame msg;
msg.messageId = kCli2Srv_Marker_ResetGame;
msg.messageBytes = sizeof(msg);
msg.recvGameId = GetGameId(); // send to GameSrv on server
msg.transId = 0;
GameMgrSend(&msg);
}
//============================================================================
void pfGmMarker::ChangeGameName (const wchar name[]) {
Cli2Srv_Marker_ChangeGameName msg;
msg.messageId = kCli2Srv_Marker_ChangeGameName;
msg.messageBytes = sizeof(msg);
msg.recvGameId = GetGameId(); // send to GameSrv on server
msg.transId = 0;
StrCopy(msg.gameName, name, arrsize(msg.gameName));
GameMgrSend(&msg);
}
//============================================================================
void pfGmMarker::ChangeTimeLimit (unsigned long timeLimit) {
Cli2Srv_Marker_ChangeTimeLimit msg;
msg.messageId = kCli2Srv_Marker_ChangeTimeLimit;
msg.messageBytes = sizeof(msg);
msg.recvGameId = GetGameId(); // send to GameSrv on server
msg.transId = 0;
msg.timeLimit = timeLimit;
GameMgrSend(&msg);
}
//============================================================================
void pfGmMarker::DeleteGame () {
Cli2Srv_Marker_DeleteGame msg;
msg.messageId = kCli2Srv_Marker_DeleteGame;
msg.messageBytes = sizeof(msg);
msg.recvGameId = GetGameId(); // send to GameSrv on server
msg.transId = 0;
GameMgrSend(&msg);
}
//============================================================================
void pfGmMarker::AddMarker (double x, double y, double z, const wchar name[], const wchar age[]) {
Cli2Srv_Marker_AddMarker msg;
msg.messageId = kCli2Srv_Marker_AddMarker;
msg.messageBytes = sizeof(msg);
msg.recvGameId = GetGameId(); // send to GameSrv on server
msg.transId = 0;
msg.x = x;
msg.y = y;
msg.z = z;
StrCopy(msg.name, name, arrsize(msg.name));
StrCopy(msg.age, age, arrsize(msg.age));
GameMgrSend(&msg);
}
//============================================================================
void pfGmMarker::DeleteMarker (unsigned long markerID) {
Cli2Srv_Marker_DeleteMarker msg;
msg.messageId = kCli2Srv_Marker_DeleteMarker;
msg.messageBytes = sizeof(msg);
msg.recvGameId = GetGameId(); // send to GameSrv on server
msg.transId = 0;
msg.markerID = markerID;
GameMgrSend(&msg);
}
//============================================================================
void pfGmMarker::ChangeMarkerName (unsigned long markerID, const wchar name[]) {
Cli2Srv_Marker_ChangeMarkerName msg;
msg.messageId = kCli2Srv_Marker_ChangeMarkerName;
msg.messageBytes = sizeof(msg);
msg.recvGameId = GetGameId(); // send to GameSrv on server
msg.transId = 0;
msg.markerID = markerID;
StrCopy(msg.markerName, name, arrsize(msg.markerName));
GameMgrSend(&msg);
}
//============================================================================
void pfGmMarker::CaptureMarker (unsigned long markerID) {
Cli2Srv_Marker_CaptureMarker msg;
msg.messageId = kCli2Srv_Marker_CaptureMarker;
msg.messageBytes = sizeof(msg);
msg.recvGameId = GetGameId(); // send to GameSrv on server
msg.transId = 0;
msg.markerID = markerID;
GameMgrSend(&msg);
}

View File

@ -0,0 +1,85 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/FeatureLib/pfGameMgr/Marker/pfGmMarker.h
*
***/
#ifdef PLASMA20_SOURCES_PLASMA_FEATURELIB_PFGAMEMGR_MARKER_PFGMMARKER_H
#error "Header $/Plasma20/Sources/Plasma/FeatureLib/pfGameMgr/Marker/pfGmMarker.h included more than once"
#endif
#define PLASMA20_SOURCES_PLASMA_FEATURELIB_PFGAMEMGR_MARKER_PFGMMARKER_H
/*****************************************************************************
*
* pfGmMarker interface
*
***/
class pfGmMarker : public pfGameCli {
// Encapsulate all implementation details such as member fields
// in an opaque friend class, in this case that's IMarker.
friend struct IMarker;
struct IMarker * internal;
//========================================================================
// Required subclass methods
//--------------------------
void Recv (GameMsgHeader * msg, void * param);
void OnPlayerJoined (const Srv2Cli_Game_PlayerJoined & msg);
void OnPlayerLeft (const Srv2Cli_Game_PlayerLeft & msg);
void OnInviteFailed (const Srv2Cli_Game_InviteFailed & msg);
void OnOwnerChange (const Srv2Cli_Game_OwnerChange & msg);
//========================================================================
public:
#pragma warning(push, 0)
// These macros produce warnings on W4
CLASSNAME_REGISTER(pfGmMarker);
GETINTERFACE_ANY(pfGmMarker, pfGameCli);
#pragma warning(pop)
pfGmMarker (unsigned gameId, plKey receiver);
~pfGmMarker ();
//========================================================================
// Game methods
//-------------
void StartGame ();
void PauseGame ();
void ResetGame ();
void ChangeGameName (const wchar name[]);
void ChangeTimeLimit (unsigned long timeLimit);
void DeleteGame ();
void AddMarker (double x, double y, double z, const wchar name[], const wchar age[]);
void DeleteMarker (unsigned long markerID);
void ChangeMarkerName (unsigned long markerID, const wchar name[]);
void CaptureMarker (unsigned long markerID);
//========================================================================
};

View File

@ -0,0 +1,57 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/FeatureLib/pfGameMgr/Pch.h
*
***/
#ifdef PLASMA20_SOURCES_PLASMA_FEATURELIB_PFGAMEMGR_PCH_H
#error "Header $/Plasma20/Sources/Plasma/FeatureLib/pfGameMgr/Pch.h included more than once"
#endif
#define PLASMA20_SOURCES_PLASMA_FEATURELIB_PFGAMEMGR_PCH_H
#include "../pnUtils/pnUtils.h"
#include "../pnNetBase/pnNetBase.h"
#include "../pnAsyncCore/pnAsyncCore.h"
#include "../pnNetCli/pnNetCli.h"
#include "../pnProduct/pnProduct.h"
#include "../pnGameMgr/pnGameMgr.h"
#include "../plNetGameLib/plNetGameLib.h"
#pragma warning(push, 0)
// These includes produce lots of warnings on W4
#include "../pnMessage/plMessage.h"
#include "../pnKeyedObject/hsKeyedObject.h"
#include "../plNetClient/plNetClientMgr.h"
#include "../pfConsole/pfConsole.h"
#pragma warning(pop)
#include "pfGameMgr.h"
#include "Intern.h"
#include <malloc.h>

View File

@ -0,0 +1,277 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/FeatureLib/pfGameMgr/TicTacToe/pfGmTicTacToe.cpp
*
***/
#define USES_GAME_TICTACTOE
#include "../Pch.h"
#pragma hdrstop
/*****************************************************************************
*
* Local types
*
***/
struct ITicTacToe {
pfGmTicTacToe * gameCli;
char board[3][3];
char myself;
char other;
ITicTacToe (pfGmTicTacToe * gameCli);
// pfGameCli event notification handlers
void Recv (GameMsgHeader * msg, void * param);
void OnPlayerJoined (const Srv2Cli_Game_PlayerJoined & msg);
void OnPlayerLeft (const Srv2Cli_Game_PlayerLeft & msg);
void OnInviteFailed (const Srv2Cli_Game_InviteFailed & msg);
void OnOwnerChange (const Srv2Cli_Game_OwnerChange & msg);
// TicTacToe network message handlers
void RecvGameStarted (const Srv2Cli_TTT_GameStarted & msg, void * param);
void RecvGameOver (const Srv2Cli_TTT_GameOver & msg, void * param);
void RecvMoveMade (const Srv2Cli_TTT_MoveMade & msg, void * param);
};
/*****************************************************************************
*
* Factory functions
*
***/
//============================================================================
static pfGameCli * TicTacToeFactory (
unsigned gameId,
plKey receiver
) {
return NEWZERO(pfGmTicTacToe)(gameId, receiver);
}
//============================================================================
AUTO_INIT_FUNC(RegisterTicTacToeFactory) {
static GameTypeReg reg = {
TicTacToeFactory,
kGameTypeId_TicTacToe,
L"Tic-Tac-Toe"
};
GameMgrRegisterGameType(reg);
}
/*****************************************************************************
*
* ITicTacToe
*
***/
//============================================================================
ITicTacToe::ITicTacToe (pfGmTicTacToe * gameCli)
: gameCli(gameCli)
{
// Fill the board with space chars
MemSet(board, ' ', sizeof(board));
}
//============================================================================
void ITicTacToe::OnPlayerJoined (const Srv2Cli_Game_PlayerJoined & msg) {
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void ITicTacToe::OnPlayerLeft (const Srv2Cli_Game_PlayerLeft & msg) {
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void ITicTacToe::OnInviteFailed (const Srv2Cli_Game_InviteFailed & msg) {
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void ITicTacToe::OnOwnerChange (const Srv2Cli_Game_OwnerChange & msg) {
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void ITicTacToe::RecvGameStarted (const Srv2Cli_TTT_GameStarted & msg, void * param) {
ref(param);
// player that goes first is shown as X's.
if (msg.yourTurn) {
myself = 'X';
other = 'O';
}
else {
myself = 'O';
other = 'X';
}
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void ITicTacToe::RecvGameOver (const Srv2Cli_TTT_GameOver & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
DEL(gameCli); // we're done
}
//============================================================================
void ITicTacToe::RecvMoveMade (const Srv2Cli_TTT_MoveMade & msg, void * param) {
ref(param);
// Update the board with the appropriate piece
if (msg.playerId == NetCommGetPlayer()->playerInt)
board[msg.row][msg.col] = myself;
else
board[msg.row][msg.col] = other;
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
/*****************************************************************************
*
* pfGmTicTacToe
*
***/
//============================================================================
pfGmTicTacToe::pfGmTicTacToe (
unsigned gameId,
plKey receiver
)
: pfGameCli(gameId, receiver)
{
internal = NEWZERO(ITicTacToe)(this);
}
//============================================================================
pfGmTicTacToe::~pfGmTicTacToe () {
DEL(internal);
}
//============================================================================
void pfGmTicTacToe::Recv (GameMsgHeader * msg, void * param) {
#define DISPATCH(a) case kSrv2Cli_TTT_##a: { \
const Srv2Cli_TTT_##a & m = *(const Srv2Cli_TTT_##a *)msg; \
internal->Recv##a(m, param); \
} \
break; //
switch (msg->messageId) {
DISPATCH(GameStarted);
DISPATCH(GameOver);
DISPATCH(MoveMade);
DEFAULT_FATAL(msg->messageId);
}
#undef DISPATCH
}
//============================================================================
void pfGmTicTacToe::OnPlayerJoined (const Srv2Cli_Game_PlayerJoined & msg) {
internal->OnPlayerJoined(msg);
}
//============================================================================
void pfGmTicTacToe::OnPlayerLeft (const Srv2Cli_Game_PlayerLeft & msg) {
internal->OnPlayerLeft(msg);
}
//============================================================================
void pfGmTicTacToe::OnInviteFailed (const Srv2Cli_Game_InviteFailed & msg) {
internal->OnInviteFailed(msg);
}
//============================================================================
void pfGmTicTacToe::OnOwnerChange (const Srv2Cli_Game_OwnerChange & msg) {
internal->OnOwnerChange(msg);
}
//============================================================================
void pfGmTicTacToe::MakeMove (unsigned row, unsigned col) {
Cli2Srv_TTT_MakeMove msg;
msg.messageId = kCli2Srv_TTT_MakeMove;
msg.messageBytes = sizeof(msg);
msg.recvGameId = GetGameId(); // send to GameSrv on server
msg.transId = 0;
msg.row = (byte)row;
msg.col = (byte)col;
GameMgrSend(&msg);
}
//============================================================================
void pfGmTicTacToe::ShowBoard () {
// Technically, we should stuff the board into a plMessage and
// have our receiver handle how the board is shown, but heck,
// this is just a little demo and not quite worth the effort.
#if 0 // Max doesn't have the console, and can't link with it anyway, so I'm removing this code since "this is just a little demo and not quite worth the effort"
pfConsole::AddLine ("\n");
pfConsole::AddLineF("\\i %c | %c | %c", internal->board[0][0], internal->board[0][1], internal->board[0][2]);
pfConsole::AddLine ("\\i---+---+---");
pfConsole::AddLineF("\\i %c | %c | %c", internal->board[1][0], internal->board[1][1], internal->board[1][2]);
pfConsole::AddLine ("\\i---+---+---");
pfConsole::AddLineF("\\i %c | %c | %c", internal->board[2][0], internal->board[2][1], internal->board[2][2]);
pfConsole::AddLine ("\n");
#endif // 0
}

View File

@ -0,0 +1,77 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/FeatureLib/pfGameMgr/TicTacToe/pfGmTicTacToe.h
*
***/
#ifdef PLASMA20_SOURCES_PLASMA_FEATURELIB_PFGAMEMGR_TICTACTOE_PFGMTICTACTOE_H
#error "Header $/Plasma20/Sources/Plasma/FeatureLib/pfGameMgr/TicTacToe/pfGmTicTacToe.h included more than once"
#endif
#define PLASMA20_SOURCES_PLASMA_FEATURELIB_PFGAMEMGR_TICTACTOE_PFGMTICTACTOE_H
/*****************************************************************************
*
* pfGmTicTacToe interface
*
***/
class pfGmTicTacToe : public pfGameCli {
// Encapsulate all implementation details such as member fields
// in an opaque friend class, in this case that's ITicTacToe.
friend struct ITicTacToe;
struct ITicTacToe * internal;
//========================================================================
// Required subclass methods
//--------------------------
void Recv (GameMsgHeader * msg, void * param);
void OnPlayerJoined (const Srv2Cli_Game_PlayerJoined & msg);
void OnPlayerLeft (const Srv2Cli_Game_PlayerLeft & msg);
void OnInviteFailed (const Srv2Cli_Game_InviteFailed & msg);
void OnOwnerChange (const Srv2Cli_Game_OwnerChange & msg);
//========================================================================
public:
#pragma warning(push, 0)
// These macros produce warnings on W4
CLASSNAME_REGISTER(pfGmTicTacToe);
GETINTERFACE_ANY(pfGmTicTacToe, pfGameCli);
#pragma warning(pop)
pfGmTicTacToe (unsigned gameId, plKey receiver);
~pfGmTicTacToe ();
//========================================================================
// Game methods
//-------------
void MakeMove (unsigned row, unsigned col);
void ShowBoard ();
//========================================================================
};

View File

@ -0,0 +1,311 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/FeatureLib/pfGameMgr/VarSync/pfGmVarSync.cpp
*
***/
#define USES_GAME_VARSYNC
#include "../Pch.h"
#pragma hdrstop
/*****************************************************************************
*
* Local types
*
***/
struct IVarSync {
pfGmVarSync * gameCli;
IVarSync (pfGmVarSync * gameCli);
// pfGameCli event notification handlers
void Recv (GameMsgHeader * msg, void * param);
void OnPlayerJoined (const Srv2Cli_Game_PlayerJoined & msg);
void OnPlayerLeft (const Srv2Cli_Game_PlayerLeft & msg);
void OnInviteFailed (const Srv2Cli_Game_InviteFailed & msg);
void OnOwnerChange (const Srv2Cli_Game_OwnerChange & msg);
// VarSync network message handlers
void RecvStringVarChanged (const Srv2Cli_VarSync_StringVarChanged & msg, void * param);
void RecvNumericVarChanged (const Srv2Cli_VarSync_NumericVarChanged & msg, void * param);
void RecvAllVarsSent (const Srv2Cli_VarSync_AllVarsSent & msg, void * param);
void RecvStringVarCreated (const Srv2Cli_VarSync_StringVarCreated & msg, void * param);
void RecvNumericVarCreated (const Srv2Cli_VarSync_NumericVarCreated & msg, void * param);
};
/*****************************************************************************
*
* Factory functions
*
***/
//============================================================================
static pfGameCli * VarSyncFactory (
unsigned gameId,
plKey receiver
) {
return NEWZERO(pfGmVarSync)(gameId, receiver);
}
//============================================================================
AUTO_INIT_FUNC(RegisterVarSyncFactory) {
static GameTypeReg reg = {
VarSyncFactory,
kGameTypeId_VarSync,
L"VarSync"
};
GameMgrRegisterGameType(reg);
}
/*****************************************************************************
*
* IVarSync
*
***/
//============================================================================
IVarSync::IVarSync (pfGmVarSync * gameCli)
: gameCli(gameCli)
{
}
//============================================================================
void IVarSync::OnPlayerJoined (const Srv2Cli_Game_PlayerJoined & msg) {
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IVarSync::OnPlayerLeft (const Srv2Cli_Game_PlayerLeft & msg) {
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IVarSync::OnInviteFailed (const Srv2Cli_Game_InviteFailed & msg) {
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IVarSync::OnOwnerChange (const Srv2Cli_Game_OwnerChange & msg) {
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IVarSync::RecvStringVarChanged (const Srv2Cli_VarSync_StringVarChanged & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IVarSync::RecvNumericVarChanged (const Srv2Cli_VarSync_NumericVarChanged & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IVarSync::RecvAllVarsSent (const Srv2Cli_VarSync_AllVarsSent & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IVarSync::RecvStringVarCreated (const Srv2Cli_VarSync_StringVarCreated & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
//============================================================================
void IVarSync::RecvNumericVarCreated (const Srv2Cli_VarSync_NumericVarCreated & msg, void * param) {
ref(param);
pfGameCliMsg * gameCliMsg = NEWZERO(pfGameCliMsg);
gameCliMsg->Set(gameCli, msg);
gameCliMsg->Send(gameCli->GetReceiver());
}
/*****************************************************************************
*
* pfGmVarSync
*
***/
//============================================================================
pfGmVarSync::pfGmVarSync (
unsigned gameId,
plKey receiver
)
: pfGameCli(gameId, receiver)
{
internal = NEWZERO(IVarSync)(this);
}
//============================================================================
pfGmVarSync::~pfGmVarSync () {
DEL(internal);
}
//============================================================================
void pfGmVarSync::Recv (GameMsgHeader * msg, void * param) {
#define DISPATCH(a) case kSrv2Cli_VarSync_##a: { \
const Srv2Cli_VarSync_##a & m = *(const Srv2Cli_VarSync_##a *)msg; \
internal->Recv##a(m, param); \
} \
break; //
switch (msg->messageId) {
DISPATCH(StringVarChanged);
DISPATCH(NumericVarChanged);
DISPATCH(AllVarsSent);
DISPATCH(StringVarCreated);
DISPATCH(NumericVarCreated);
DEFAULT_FATAL(msg->messageId);
}
#undef DISPATCH
}
//============================================================================
void pfGmVarSync::OnPlayerJoined (const Srv2Cli_Game_PlayerJoined & msg) {
internal->OnPlayerJoined(msg);
}
//============================================================================
void pfGmVarSync::OnPlayerLeft (const Srv2Cli_Game_PlayerLeft & msg) {
internal->OnPlayerLeft(msg);
}
//============================================================================
void pfGmVarSync::OnInviteFailed (const Srv2Cli_Game_InviteFailed & msg) {
internal->OnInviteFailed(msg);
}
//============================================================================
void pfGmVarSync::OnOwnerChange (const Srv2Cli_Game_OwnerChange & msg) {
internal->OnOwnerChange(msg);
}
//============================================================================
void pfGmVarSync::SetStringVar (unsigned long id, const wchar* val) {
Cli2Srv_VarSync_SetStringVar msg;
msg.messageId = kCli2Srv_VarSync_SetStringVar;
msg.messageBytes = sizeof(msg);
msg.recvGameId = GetGameId(); // send to GameSrv on server
msg.transId = 0;
msg.varID = id;
StrCopy(msg.varValue, val, arrsize(msg.varValue));
GameMgrSend(&msg);
}
//============================================================================
void pfGmVarSync::SetNumericVar (unsigned long id, double val) {
Cli2Srv_VarSync_SetNumericVar msg;
msg.messageId = kCli2Srv_VarSync_SetNumericVar;
msg.messageBytes = sizeof(msg);
msg.recvGameId = GetGameId(); // send to GameSrv on server
msg.transId = 0;
msg.varID = id;
msg.varValue = val;
GameMgrSend(&msg);
}
//============================================================================
void pfGmVarSync::RequestAllVars () {
Cli2Srv_VarSync_RequestAllVars msg;
msg.messageId = kCli2Srv_VarSync_RequestAllVars;
msg.messageBytes = sizeof(msg);
msg.recvGameId = GetGameId(); // send to GameSrv on server
msg.transId = 0;
GameMgrSend(&msg);
}
//============================================================================
void pfGmVarSync::CreateStringVar (const wchar* name, const wchar* val) {
Cli2Srv_VarSync_CreateStringVar msg;
msg.messageId = kCli2Srv_VarSync_CreateStringVar;
msg.messageBytes = sizeof(msg);
msg.recvGameId = GetGameId(); // send to GameSrv on server
msg.transId = 0;
StrCopy(msg.varName, name, arrsize(msg.varName));
StrCopy(msg.varValue, val, arrsize(msg.varValue));
GameMgrSend(&msg);
}
//============================================================================
void pfGmVarSync::CreateNumericVar (const wchar* name, double val) {
Cli2Srv_VarSync_CreateNumericVar msg;
msg.messageId = kCli2Srv_VarSync_CreateNumericVar;
msg.messageBytes = sizeof(msg);
msg.recvGameId = GetGameId(); // send to GameSrv on server
msg.transId = 0;
StrCopy(msg.varName, name, arrsize(msg.varName));
msg.varValue = val;
GameMgrSend(&msg);
}

View File

@ -0,0 +1,80 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/FeatureLib/pfGameMgr/VarSync/pfGmVarSync.h
*
***/
#ifdef PLASMA20_SOURCES_PLASMA_FEATURELIB_PFGAMEMGR_VARSYNC_PFGMVARSYNC_H
#error "Header $/Plasma20/Sources/Plasma/FeatureLib/pfGameMgr/VarSync/pfGmVarSync.h included more than once"
#endif
#define PLASMA20_SOURCES_PLASMA_FEATURELIB_PFGAMEMGR_VARSYNC_PFGMVARSYNC_H
/*****************************************************************************
*
* pfGmVarSync interface
*
***/
class pfGmVarSync : public pfGameCli {
// Encapsulate all implementation details such as member fields
// in an opaque friend class, in this case that's IVarSync.
friend struct IVarSync;
struct IVarSync * internal;
//========================================================================
// Required subclass methods
//--------------------------
void Recv (GameMsgHeader * msg, void * param);
void OnPlayerJoined (const Srv2Cli_Game_PlayerJoined & msg);
void OnPlayerLeft (const Srv2Cli_Game_PlayerLeft & msg);
void OnInviteFailed (const Srv2Cli_Game_InviteFailed & msg);
void OnOwnerChange (const Srv2Cli_Game_OwnerChange & msg);
//========================================================================
public:
#pragma warning(push, 0)
// These macros produce warnings on W4
CLASSNAME_REGISTER(pfGmVarSync);
GETINTERFACE_ANY(pfGmVarSync, pfGameCli);
#pragma warning(pop)
pfGmVarSync (unsigned gameId, plKey receiver);
~pfGmVarSync ();
//========================================================================
// Game methods
//-------------
void SetStringVar (unsigned long id, const wchar* val);
void SetNumericVar (unsigned long id, double val);
void RequestAllVars ();
void CreateStringVar (const wchar* name, const wchar* val);
void CreateNumericVar (const wchar* name, double val);
//========================================================================
};

View File

@ -0,0 +1,657 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/FeatureLib/pfGameMgr/pfGameMgr.cpp
*
***/
#include "Pch.h"
#pragma hdrstop
/*****************************************************************************
*
* Local types
*
***/
//============================================================================
// pfGameCli factory
//============================================================================
struct Factory : THashKeyVal<Uuid> {
HASHLINK(Factory) link;
const GameTypeReg & reg;
Factory (const GameTypeReg & reg);
operator= (const Factory &); // not impl
};
//============================================================================
// pfGameCli internal state
//============================================================================
struct IGameCli : THashKeyVal<unsigned> {
HASHLINK(IGameCli) link;
pfGameCli * gameCli;
Factory * factory;
plKey receiver;
unsigned playerCount;
IGameCli (
pfGameCli * gameCli,
unsigned gameId,
plKey receiver
);
void Recv (GameMsgHeader * msg, void * param);
void RecvPlayerJoined (const Srv2Cli_Game_PlayerJoined & msg, void * param);
void RecvPlayerLeft (const Srv2Cli_Game_PlayerLeft & msg, void * param);
void RecvInviteFailed (const Srv2Cli_Game_InviteFailed & msg, void * param);
void RecvOwnerChange (const Srv2Cli_Game_OwnerChange & msg, void * param);
};
//============================================================================
// Transaction states
//============================================================================
struct TransState : THashKeyVal<unsigned> {
HASHLINK(TransState) link;
void * param;
TransState (unsigned transId, void * param);
};
struct JoinTransState {
plKey receiver;
JoinTransState (plKey receiver)
: receiver(receiver)
{ }
};
//============================================================================
// IGameMgr
//============================================================================
struct IGameMgr {
pfGameCli * CreateGameCli (const Uuid & gameTypeId, unsigned gameId, plKey receiver);
void Recv (GameMsgHeader * msg);
void RecvGameInstance (const Srv2Cli_GameMgr_GameInstance & msg, void * param);
void RecvInviteReceived (const Srv2Cli_GameMgr_InviteReceived & msg, void * param);
void RecvInviteRevoked (const Srv2Cli_GameMgr_InviteRevoked & msg, void * param);
static void StaticRecv (GameMsgHeader * msg);
};
/*****************************************************************************
*
* Local data
*
***/
static HASHTABLEDECL(TransState, THashKeyVal<unsigned>, link) s_trans;
static HASHTABLEDECL(IGameCli, THashKeyVal<unsigned>, link) s_games;
static HASHTABLEDECL(Factory, THashKeyVal<Uuid>, link) s_factories;
static long s_transId;
static ARRAYOBJ(plKey) s_receivers;
/*****************************************************************************
*
* Local functions
*
***/
//============================================================================
static void ShutdownFactories () {
while (Factory * factory = s_factories.Head())
DEL(factory);
}
//============================================================================
AUTO_INIT_FUNC (SetGameMgrMsgHandler) {
NetCliGameSetRecvGameMgrMsgHandler(IGameMgr::StaticRecv);
atexit(ShutdownFactories);
}
//============================================================================
static inline unsigned INextTransId () {
unsigned transId = AtomicAdd(&s_transId, 1);
while (!transId)
transId = AtomicAdd(&s_transId, 1);
return transId;
}
/*****************************************************************************
*
* IGameMgr
*
***/
//============================================================================
pfGameCli * IGameMgr::CreateGameCli (const Uuid & gameTypeId, unsigned gameId, plKey receiver) {
if (Factory * factory = s_factories.Find(gameTypeId)) {
pfGameCli * gameCli = factory->reg.create(gameId, receiver);
gameCli->internal->factory = factory;
return gameCli;
}
return nil;
}
//============================================================================
void IGameMgr::RecvGameInstance (const Srv2Cli_GameMgr_GameInstance & msg, void * param) {
JoinTransState * state = (JoinTransState *)param;
pfGameCli * cli = nil;
IGameCli * internal = nil;
if (msg.result == kGameJoinSuccess) {
if (nil == (internal = s_games.Find(msg.newGameId)))
cli = CreateGameCli(msg.gameTypeId, msg.newGameId, state->receiver);
else
cli = internal->gameCli;
}
DEL(state);
}
//============================================================================
void IGameMgr::RecvInviteReceived (const Srv2Cli_GameMgr_InviteReceived & msg, void * param) {
ref(param);
pfGameMgrMsg * gameMgrMsg = NEWZERO(pfGameMgrMsg);
gameMgrMsg->Set(msg);
for (unsigned i = 0; i < s_receivers.Count(); ++i)
gameMgrMsg->AddReceiver(s_receivers[i]);
gameMgrMsg->Send();
}
//============================================================================
void IGameMgr::RecvInviteRevoked (const Srv2Cli_GameMgr_InviteRevoked & msg, void * param) {
ref(param);
pfGameMgrMsg * gameMgrMsg = NEWZERO(pfGameMgrMsg);
gameMgrMsg->Set(msg);
for (unsigned i = 0; i < s_receivers.Count(); ++i)
gameMgrMsg->AddReceiver(s_receivers[i]);
gameMgrMsg->Send();
}
//============================================================================
void IGameMgr::Recv (GameMsgHeader * msg) {
// Look for transaction state associated with this message
void * param;
if (TransState * trans = s_trans.Find(msg->transId)) {
param = trans->param;
DEL(trans);
}
else {
param = nil;
}
// If the message has a receiver gameId specified, then
// hand it off to that game client for dispatch.
if (unsigned gameId = msg->recvGameId) {
if (IGameCli * node = s_games.Find(gameId)) {
node->Recv(msg, param);
}
return;
}
// The message was meant for the game manager (that's us); dispatch it.
#define DISPATCH(a) case kSrv2Cli_GameMgr_##a: { \
const Srv2Cli_GameMgr_##a & m = *(const Srv2Cli_GameMgr_##a *)msg; \
Recv##a(m, param); \
} \
break; //
switch (msg->messageId) {
DISPATCH(GameInstance);
DISPATCH(InviteReceived);
DISPATCH(InviteRevoked);
DEFAULT_FATAL(msg->messageId);
}
#undef DISPATCH
}
//============================================================================
void IGameMgr::StaticRecv (GameMsgHeader * msg) {
pfGameMgr::GetInstance()->internal->Recv(msg);
}
/*****************************************************************************
*
* pfGameMgrMsg
*
***/
//============================================================================
pfGameMgrMsg::pfGameMgrMsg () {
netMsg = nil;
}
//============================================================================
pfGameMgrMsg::~pfGameMgrMsg () {
FREE(netMsg);
}
//============================================================================
void pfGameMgrMsg::Set (const GameMsgHeader & msg) {
netMsg = (GameMsgHeader *)ALLOC(msg.messageBytes);
MemCopy(netMsg, &msg, msg.messageBytes);
}
/*****************************************************************************
*
* pfGameCliMsg
*
***/
//============================================================================
pfGameCliMsg::pfGameCliMsg () {
gameCli = nil;
netMsg = nil;
}
//============================================================================
pfGameCliMsg::~pfGameCliMsg () {
FREE(netMsg);
}
//============================================================================
void pfGameCliMsg::Set (pfGameCli * cli, const GameMsgHeader & msg) {
netMsg = (GameMsgHeader *)ALLOC(msg.messageBytes);
MemCopy(netMsg, &msg, msg.messageBytes);
gameCli = cli;
}
/*****************************************************************************
*
* pfGameMgr
*
***/
//============================================================================
pfGameMgr::pfGameMgr () {
}
//============================================================================
pfGameMgr * pfGameMgr::GetInstance () {
static pfGameMgr s_instance;
return &s_instance;
}
//============================================================================
void pfGameMgr::GetGameIds (ARRAY(unsigned) * arr) const {
for (IGameCli * node = s_games.Head(); node; node = s_games.Next(node))
arr->Add(node->GetValue());
}
//============================================================================
pfGameCli * pfGameMgr::GetGameCli (unsigned gameId) const {
if (IGameCli * node = s_games.Find(gameId))
return node->gameCli;
return nil;
}
//============================================================================
const wchar * pfGameMgr::GetGameNameByTypeId (const Uuid & gameTypeId) const {
if (Factory * factory = s_factories.Find(gameTypeId))
return factory->reg.name;
return nil;
}
//============================================================================
void pfGameMgr::RemoveReceiver (plKey receiver) {
for (unsigned i = 0; i < s_receivers.Count(); ++i) {
if (s_receivers[i] == receiver) {
s_receivers.DeleteUnordered(i);
break;
}
}
}
//============================================================================
void pfGameMgr::AddReceiver (plKey receiver) {
RemoveReceiver(receiver);
s_receivers.Add(receiver);
}
//============================================================================
void pfGameMgr::JoinGame (
plKey receiver,
unsigned gameId
) {
Cli2Srv_GameMgr_JoinGame msg;
ZERO(msg);
msg.messageId = kCli2Srv_GameMgr_JoinGame;
msg.recvGameId = 0; // send to GameMgr on server
msg.newGameId = gameId; // the GameSrv we wish to join
// Don't send "common game" message fields
unsigned msgBytes
= sizeof(msg)
- sizeof(msg.gameTypeId)
- sizeof(msg.createDataBytes)
- sizeof(msg.createData);
msg.messageBytes = msgBytes;
GameMgrSend(&msg, NEWZERO(JoinTransState)(receiver));
}
//============================================================================
void pfGameMgr::CreateGame (
plKey receiver,
const Uuid & gameTypeId,
unsigned createOptions,
unsigned initBytes,
const void * initData
) {
Cli2Srv_GameMgr_CreateGame * msg;
unsigned msgBytes
= sizeof(*msg)
- sizeof(msg->createData)
+ initBytes;
msg = (Cli2Srv_GameMgr_CreateGame *)_alloca(msgBytes);
msg->messageId = kCli2Srv_GameMgr_CreateGame;
msg->recvGameId = 0; // send to GameMgr on server
msg->gameTypeId = gameTypeId; // The type of game we wish to create
msg->createOptions = createOptions;
msg->messageBytes = msgBytes;
msg->createDataBytes = initBytes;
MemCopy(msg->createData, initData, initBytes);
GameMgrSend(msg, NEWZERO(JoinTransState)(receiver));
}
//============================================================================
void pfGameMgr::JoinCommonGame (
plKey receiver,
const Uuid & gameTypeId,
unsigned gameNumber,
unsigned initBytes,
const void * initData
) {
Cli2Srv_GameMgr_JoinGame * msg;
unsigned msgBytes
= sizeof(*msg)
- sizeof(msg->createData)
+ initBytes;
msg = (Cli2Srv_GameMgr_JoinGame *)_alloca(msgBytes);
msg->messageId = kCli2Srv_GameMgr_JoinGame;
msg->recvGameId = 0; // send to GameMgr on server
msg->gameTypeId = gameTypeId; // the type of common game we with to join
msg->newGameId = gameNumber; // the "table number" of th common game we wish to join
msg->createOptions = kGameJoinCommon;
msg->messageBytes = msgBytes;
msg->createDataBytes = initBytes;
MemCopy(msg->createData, initData, initBytes);
GameMgrSend(msg, NEWZERO(JoinTransState)(receiver));
}
/*****************************************************************************
*
* pfGameCli
*
***/
//============================================================================
pfGameCli::pfGameCli (
unsigned gameId,
plKey receiver
) {
internal = NEWZERO(IGameCli)(this, gameId, receiver);
}
//============================================================================
pfGameCli::~pfGameCli () {
DEL(internal);
}
//============================================================================
unsigned pfGameCli::GetGameId () const {
return internal->GetValue();
}
//============================================================================
const Uuid & pfGameCli::GetGameTypeId () const {
return internal->factory->GetValue();
}
//============================================================================
const wchar * pfGameCli::GetName () const {
return internal->factory->reg.name;
}
//============================================================================
plKey pfGameCli::GetReceiver () const {
return internal->receiver;
}
//============================================================================
unsigned pfGameCli::GetPlayerCount () const {
return internal->playerCount;
}
//============================================================================
void pfGameCli::InvitePlayer (unsigned playerId) {
Cli2Srv_Game_Invite msg;
msg.messageId = kCli2Srv_Game_Invite;
msg.recvGameId = GetGameId(); // send to GameSrv on server
msg.playerId = playerId;
msg.messageBytes = sizeof(msg);
GameMgrSend(&msg);
}
//============================================================================
void pfGameCli::UninvitePlayer (unsigned playerId) {
Cli2Srv_Game_Uninvite msg;
msg.messageId = kCli2Srv_Game_Uninvite;
msg.recvGameId = GetGameId(); // send to GameSrv on server
msg.playerId = playerId;
msg.messageBytes = sizeof(msg);
GameMgrSend(&msg);
}
//============================================================================
void pfGameCli::LeaveGame () {
Cli2Srv_Game_LeaveGame msg;
msg.messageId = kCli2Srv_Game_LeaveGame;
msg.recvGameId = GetGameId(); // send to GameSrv on server
msg.messageBytes = sizeof(msg);
GameMgrSend(&msg);
}
/*****************************************************************************
*
* IGameCli
*
***/
//============================================================================
IGameCli::IGameCli (
pfGameCli * gameCli,
unsigned gameId,
plKey receiver
) : THashKeyVal<unsigned>(gameId)
, gameCli(gameCli)
, receiver(receiver)
{
s_games.Add(this);
}
//============================================================================
void IGameCli::Recv (GameMsgHeader * msg, void * param) {
#define DISPATCH(a) case kSrv2Cli_Game_##a: { \
const Srv2Cli_Game_##a & m = *(const Srv2Cli_Game_##a *)msg; \
Recv##a(m, param); \
} \
break;
switch (msg->messageId) {
DISPATCH(PlayerJoined);
DISPATCH(PlayerLeft);
DISPATCH(InviteFailed);
DISPATCH(OwnerChange);
default:
gameCli->Recv(msg, param);
}
#undef DISPATCH
}
//============================================================================
void IGameCli::RecvPlayerJoined (const Srv2Cli_Game_PlayerJoined & msg, void * param) {
ref(param);
++playerCount;
gameCli->OnPlayerJoined(msg);
}
//============================================================================
void IGameCli::RecvPlayerLeft (const Srv2Cli_Game_PlayerLeft & msg, void * param) {
ref(param);
--playerCount;
gameCli->OnPlayerLeft(msg);
}
//============================================================================
void IGameCli::RecvInviteFailed (const Srv2Cli_Game_InviteFailed & msg, void * param) {
ref(param);
gameCli->OnInviteFailed(msg);
}
//============================================================================
void IGameCli::RecvOwnerChange (const Srv2Cli_Game_OwnerChange & msg, void * param) {
ref(param);
gameCli->OnOwnerChange(msg);
}
/*****************************************************************************
*
* Factory
*
***/
//============================================================================
Factory::Factory (const GameTypeReg & reg)
: reg(reg)
, THashKeyVal<Uuid>(reg.typeId)
{
s_factories.Add(this);
}
/*****************************************************************************
*
* TransState
*
***/
//============================================================================
TransState::TransState (unsigned transId, void * param)
: THashKeyVal<unsigned>(transId)
, param(param)
{
s_trans.Add(this);
}
/*****************************************************************************
*
* Module functions
*
***/
//============================================================================
void GameMgrRegisterGameType (const GameTypeReg & reg) {
(void)NEWZERO(Factory)(reg);
}
//============================================================================
void GameMgrSend (GameMsgHeader * msg, void * param) {
if (param) {
msg->transId = INextTransId();
(void)NEW(TransState)(msg->transId, param);
}
else {
msg->transId = 0;
}
NetCliGameSendGameMgrMsg(msg);
}

View File

@ -0,0 +1,256 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/FeatureLib/pfGameMgr/pfGameMgr.h
*
***/
#ifndef PLASMA20_SOURCES_PLASMA_FEATURELIB_PFGAMEMGR_PFGAMEMGR_H
#define PLASMA20_SOURCES_PLASMA_FEATURELIB_PFGAMEMGR_PFGAMEMGR_H
#include "../pnUtils/pnUtils.h"
#include "../pnNetBase/pnNetBase.h"
#include "../pnAsyncCore/pnAsyncCore.h"
#include "../pnNetCli/pnNetCli.h"
#include "../pnProduct/pnProduct.h"
#include "../plNetGameLib/plNetGameLib.h"
#pragma warning(push, 0)
// These includes produce lots of warnings on W4
#include "../pnMessage/plMessage.h"
#include "../pnKeyedObject/hsKeyedObject.h"
#pragma warning(pop)
//============================================================================
// Forward declarations
//============================================================================
class pfGameCli;
//============================================================================
// pfGameMgrMsg
//-------------
// Notifications received from SrvGameMgr are sent to pfGameMgr's receivers in
// the form of a pfGameMgrMsg.
//============================================================================
class pfGameMgrMsg : public plMessage {
public:
#pragma warning(push, 0)
// These macros produce warnings on W4
CLASSNAME_REGISTER(pfGameMgrMsg);
GETINTERFACE_ANY(pfGameMgrMsg, plMessage);
#pragma warning(pop)
void Read(hsStream *, hsResMgr *) { FATAL("not impl"); }
void Write(hsStream *, hsResMgr *) { FATAL("not impl"); }
pfGameMgrMsg ();
~pfGameMgrMsg ();
void Set (const GameMsgHeader & msg);
GameMsgHeader * netMsg;
};
//============================================================================
// pfGameCliMsg
//-------------
// Notifications received by a pfGameCli are sent to its receiver in the form
// of a pfGameCliMsg.
//============================================================================
class pfGameCliMsg : public plMessage {
public:
#pragma warning(push, 0)
// These macros produce warnings on W4
CLASSNAME_REGISTER(pfGameCliMsg);
GETINTERFACE_ANY(pfGameCliMsg, plMessage);
#pragma warning(pop)
pfGameCliMsg ();
~pfGameCliMsg ();
void Read(hsStream *, hsResMgr *) { FATAL("not impl"); }
void Write(hsStream *, hsResMgr *) { FATAL("not impl"); }
void Set (pfGameCli * cli, const GameMsgHeader & msg);
pfGameCli * gameCli;
GameMsgHeader * netMsg;
};
//============================================================================
// pfGameMgr singleton interface
//------------------------------
// pfGameMgr is the client-side proxy of the age server's SrvGameMgr. It sends
// client requests to the SrvGameMgr for processing, and executes SrvGameMgr
// commands locally to create pfGameCli objects, notify player of received
// game invites, etc.
//============================================================================
class pfGameMgr {
friend struct IGameMgr;
struct IGameMgr * internal;
pfGameMgr ();
public:
static pfGameMgr * GetInstance ();
//========================================================================
// Receiver list
//--------------
// When notificatons are received from SrvGameMgr, they are dispatched
// as pfGameMgrMsgs to the receiver list maintained by these functions.
void AddReceiver (plKey receiver);
void RemoveReceiver (plKey receiver);
//========================================================================
//========================================================================
// GameMgr properties
//-------------------
// Get a list of ids of games to which player is joined
void GetGameIds (ARRAY(unsigned) * arr) const;
// Return interface to the specified game
pfGameCli * GetGameCli (unsigned gameId) const;
// Get the name of a game by its typeid
const wchar * GetGameNameByTypeId (const Uuid & gameTypeId) const;
//========================================================================
//========================================================================
// pfGameCli creation
//-------------------
// Join an existing game
void JoinGame (
plKey receiver, // Receiver of pfGameCliMsgs for this game
unsigned gameId // id of the game to join
);
// Create a new game
void CreateGame (
plKey receiver, // Receiver of pfGameCliMsgs for this game
const Uuid & gameTypeId, // typeid of game to create
unsigned createOptions, // Game create options from pnGameMgr.h
unsigned initBytes, // Game-specific initialization data
const void * initData
);
// Join or create the specified common game
void JoinCommonGame (
plKey receiver, // Receiver of pfGameCliMsgs for this game
const Uuid & gameTypeId, // typeid of common game to create/join
unsigned gameNumber, // "table number" of common game to create/join
// In case the common game needs to
// be created on the server, these
// are its creation parameters:
unsigned initBytes, // Game-specific initialization data
const void * initData
);
//========================================================================
//========================================================================
// @@@: FUTURE WORK
//-----------------
// Fetch the list of games registered with SrvGameMgr's matchmaking service.
// void RequestPublishedGameList ();
//========================================================================
};
//============================================================================
// pfGameCli interface
//============================================================================
class pfGameCli : public plCreatable {
friend struct IGameMgr;
friend struct IGameCli;
struct IGameCli * internal;
//========================================================================
// sub-classes must implement these
virtual void Recv (GameMsgHeader * msg, void * param) = 0;
virtual void OnPlayerJoined (const Srv2Cli_Game_PlayerJoined & msg) = 0;
virtual void OnPlayerLeft (const Srv2Cli_Game_PlayerLeft & msg) = 0;
virtual void OnInviteFailed (const Srv2Cli_Game_InviteFailed & msg) = 0;
virtual void OnOwnerChange (const Srv2Cli_Game_OwnerChange & msg) = 0;
//========================================================================
public:
#pragma warning(push, 0)
// These macros produce warnings on W4
CLASSNAME_REGISTER(pfGameCli);
GETINTERFACE_ANY(pfGameCli, plCreatable);
#pragma warning(pop)
pfGameCli (unsigned gameId, plKey receiver);
~pfGameCli ();
//========================================================================
// Game client properties
//-----------------------
unsigned GetGameId () const;
const Uuid & GetGameTypeId () const;
const wchar * GetName () const;
plKey GetReceiver () const;
unsigned GetPlayerCount () const;
//========================================================================
//========================================================================
// Player invitation management
//-----------------------------
void InvitePlayer (unsigned playerId);
void UninvitePlayer (unsigned playerId);
//========================================================================
//========================================================================
// Game methods
//-------------
void LeaveGame ();
//========================================================================
//========================================================================
// @@@: FUTURE WORK
//-----------------
// "Publish" this game, adding it to the age's the matchmaking service.
// void PublishGame (const wchar desc[]);
// void UnpublishGame ();
//========================================================================
};
/*****************************************************************************
*
* Games
*
***/
#include "TicTacToe/pfGmTicTacToe.h"
#include "Heek/pfGmHeek.h"
#include "Marker/pfGmMarker.h"
#include "BlueSpiral/pfGmBlueSpiral.h"
#include "ClimbingWall/pfGmClimbingWall.h"
#include "VarSync/pfGmVarSync.h"
#endif // PLASMA20_SOURCES_PLASMA_FEATURELIB_PFGAMEMGR_PFGAMEMGR_H

View File

@ -0,0 +1,49 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/FeatureLib/pfGameMgr/pfGameMgrCreatables.h
*
***/
#ifndef PLASMA20_SOURCES_PLASMA_FEATURELIB_PFGAMEMGR_PFGAMEMGRCREATABLES_H
#define PLASMA20_SOURCES_PLASMA_FEATURELIB_PFGAMEMGR_PFGAMEMGRCREATABLES_H
#include "pfGameMgr.h"
REGISTER_CREATABLE(pfGameMgrMsg);
REGISTER_CREATABLE(pfGameCliMsg);
REGISTER_NONCREATABLE(pfGameCli);
REGISTER_NONCREATABLE(pfGmTicTacToe);
REGISTER_NONCREATABLE(pfGmHeek);
REGISTER_NONCREATABLE(pfGmMarker);
REGISTER_NONCREATABLE(pfGmBlueSpiral);
REGISTER_NONCREATABLE(pfGmClimbingWall);
REGISTER_NONCREATABLE(pfGmVarSync);
#endif // PLASMA20_SOURCES_PLASMA_FEATURELIB_PFGAMEMGR_PFGAMEMGRCREATABLES_H