2010-03-27 07:09:34 +00:00
|
|
|
|
// ==============================================================
|
|
|
|
|
// This file is part of Glest (www.glest.org)
|
|
|
|
|
//
|
2010-04-21 23:13:39 +00:00
|
|
|
|
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
2010-03-27 07:09:34 +00:00
|
|
|
|
//
|
|
|
|
|
// You can redistribute this code and/or modify it under
|
|
|
|
|
// the terms of the GNU General Public License as published
|
|
|
|
|
// by the Free Software Foundation; either version 2 of the
|
|
|
|
|
// License, or (at your option) any later version
|
|
|
|
|
// ==============================================================
|
|
|
|
|
|
|
|
|
|
#ifndef _GLEST_GAME_SERVERINTERFACE_H_
|
|
|
|
|
#define _GLEST_GAME_SERVERINTERFACE_H_
|
|
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
#include "game_constants.h"
|
|
|
|
|
#include "network_interface.h"
|
|
|
|
|
#include "connection_slot.h"
|
|
|
|
|
#include "socket.h"
|
2010-09-07 05:25:40 +00:00
|
|
|
|
#include "leak_dumper.h"
|
2010-03-27 07:09:34 +00:00
|
|
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
|
using Shared::Platform::ServerSocket;
|
|
|
|
|
|
|
|
|
|
namespace Glest{ namespace Game{
|
|
|
|
|
|
2010-05-15 18:59:17 +00:00
|
|
|
|
// =====================================================
|
|
|
|
|
// class ServerInterface
|
|
|
|
|
// =====================================================
|
|
|
|
|
|
|
|
|
|
class ServerInterface: public GameNetworkInterface, public ConnectionSlotCallbackInterface {
|
2010-03-27 07:09:34 +00:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
ConnectionSlot* slots[GameConstants::maxPlayers];
|
|
|
|
|
ServerSocket serverSocket;
|
|
|
|
|
bool gameHasBeenInitiated;
|
|
|
|
|
int gameSettingsUpdateCount;
|
2010-04-28 23:59:37 +00:00
|
|
|
|
SwitchSetupRequest* switchSetupRequests[GameConstants::maxPlayers];
|
2010-05-15 18:59:17 +00:00
|
|
|
|
Mutex serverSynchAccessor;
|
2010-06-15 05:36:07 +00:00
|
|
|
|
int currentFrameCount;
|
2010-05-15 18:59:17 +00:00
|
|
|
|
|
2010-06-28 00:21:12 +00:00
|
|
|
|
time_t gameStartTime;
|
2010-03-27 07:09:34 +00:00
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
ServerInterface();
|
|
|
|
|
virtual ~ServerInterface();
|
|
|
|
|
|
|
|
|
|
virtual Socket* getSocket() {return &serverSocket;}
|
|
|
|
|
virtual const Socket* getSocket() const {return &serverSocket;}
|
|
|
|
|
virtual void close();
|
|
|
|
|
|
|
|
|
|
//message processing
|
|
|
|
|
virtual void update();
|
|
|
|
|
virtual void updateLobby(){};
|
|
|
|
|
virtual void updateKeyframe(int frameCount);
|
|
|
|
|
virtual void waitUntilReady(Checksum* checksum);
|
|
|
|
|
|
|
|
|
|
// message sending
|
2010-07-01 00:08:59 +00:00
|
|
|
|
virtual void sendTextMessage(const string &text, int teamIndex, bool echoLocal=false);
|
2010-03-27 07:09:34 +00:00
|
|
|
|
virtual void quitGame(bool userManuallyQuit);
|
|
|
|
|
|
|
|
|
|
//misc
|
2010-06-04 19:42:58 +00:00
|
|
|
|
virtual string getNetworkStatus() ;
|
2010-03-27 07:09:34 +00:00
|
|
|
|
|
|
|
|
|
ServerSocket* getServerSocket() {return &serverSocket;}
|
2010-04-28 23:59:37 +00:00
|
|
|
|
SwitchSetupRequest** getSwitchSetupRequests() {return &switchSetupRequests[0];}
|
2010-03-27 07:09:34 +00:00
|
|
|
|
void addSlot(int playerIndex);
|
2010-04-30 01:08:29 +00:00
|
|
|
|
bool switchSlot(int fromPlayerIndex,int toPlayerIndex);
|
2010-03-27 07:09:34 +00:00
|
|
|
|
void removeSlot(int playerIndex);
|
|
|
|
|
ConnectionSlot* getSlot(int playerIndex);
|
|
|
|
|
int getConnectedSlotCount();
|
2010-05-12 15:25:56 +00:00
|
|
|
|
int getOpenSlotCount();
|
2010-03-27 07:09:34 +00:00
|
|
|
|
|
|
|
|
|
bool launchGame(const GameSettings* gameSettings);
|
2010-08-26 19:01:44 +00:00
|
|
|
|
void setGameSettings(GameSettings *serverGameSettings, bool waitForClientAck);
|
2010-04-21 23:13:39 +00:00
|
|
|
|
void broadcastGameSetup(const GameSettings* gameSettings);
|
2010-05-12 15:25:56 +00:00
|
|
|
|
void updateListen();
|
2010-05-13 07:13:53 +00:00
|
|
|
|
virtual bool getConnectHasHandshaked() const { return false; }
|
2010-03-27 07:09:34 +00:00
|
|
|
|
|
2010-05-15 18:59:17 +00:00
|
|
|
|
virtual void slotUpdateTask(ConnectionSlotEvent *event);
|
2010-05-17 06:41:05 +00:00
|
|
|
|
bool hasClientConnection();
|
2010-06-15 05:36:07 +00:00
|
|
|
|
int getCurrentFrameCount() const { return currentFrameCount; }
|
2010-08-07 03:26:38 +00:00
|
|
|
|
std::pair<bool,bool> clientLagCheck(ConnectionSlot* connectionSlot,bool skipNetworkBroadCast=false);
|
2010-05-15 18:59:17 +00:00
|
|
|
|
|
2010-06-29 06:50:35 +00:00
|
|
|
|
bool signalClientReceiveCommands(ConnectionSlot* connectionSlot,
|
2010-06-17 21:46:36 +00:00
|
|
|
|
int slotIndex,
|
|
|
|
|
bool socketTriggered,
|
|
|
|
|
ConnectionSlotEvent &event);
|
|
|
|
|
void updateSocketTriggeredList(std::map<PLATFORM_SOCKET,bool> &socketTriggeredList);
|
|
|
|
|
|
2010-06-24 01:23:18 +00:00
|
|
|
|
bool isPortBound() const { return serverSocket.isPortBound(); }
|
|
|
|
|
int getBindPort() const { return serverSocket.getBindPort(); }
|
|
|
|
|
|
2010-07-09 17:12:57 +00:00
|
|
|
|
void broadcastPing(const NetworkMessagePing* networkMessage, int excludeSlot= -1) {
|
|
|
|
|
this->broadcastMessage(networkMessage,excludeSlot);
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-21 13:04:52 +00:00
|
|
|
|
virtual string getHumanPlayerName(int index=-1);
|
|
|
|
|
|
2010-05-21 16:36:08 +00:00
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
Mutex * getServerSynchAccessor() { return &serverSynchAccessor; }
|
|
|
|
|
|
2010-03-27 07:09:34 +00:00
|
|
|
|
private:
|
2010-05-21 16:36:08 +00:00
|
|
|
|
|
2010-03-27 07:09:34 +00:00
|
|
|
|
void broadcastMessage(const NetworkMessage* networkMessage, int excludeSlot= -1);
|
|
|
|
|
void broadcastMessageToConnectedClients(const NetworkMessage* networkMessage, int excludeSlot = -1);
|
2010-05-04 02:32:43 +00:00
|
|
|
|
bool shouldDiscardNetworkMessage(NetworkMessageType networkMessageType,ConnectionSlot* connectionSlot);
|
2010-05-15 18:59:17 +00:00
|
|
|
|
void updateSlot(ConnectionSlotEvent *event);
|
2010-08-20 20:03:06 +00:00
|
|
|
|
void validateConnectedClients();
|
2010-03-27 07:09:34 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}}//end namespace
|
|
|
|
|
|
|
|
|
|
#endif
|