2009-04-18 19:00:33 +02:00
|
|
|
/* Copyright (C) 2009 Wildfire Games.
|
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. 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 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. 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 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#ifndef INCLUDED_NETWORK_JSEVENTS
|
|
|
|
#define INCLUDED_NETWORK_JSEVENTS
|
2005-02-02 17:57:15 +01:00
|
|
|
|
2006-06-02 05:56:24 +02:00
|
|
|
#include "ServerSession.h"
|
2006-06-09 20:32:00 +02:00
|
|
|
#include "scripting/DOMEvent.h"
|
2005-02-21 18:13:31 +01:00
|
|
|
|
2005-02-02 17:57:15 +01:00
|
|
|
enum ENetworkJSEvents
|
|
|
|
{
|
|
|
|
NET_JS_EVENT_START_GAME,
|
|
|
|
NET_JS_EVENT_CHAT,
|
|
|
|
NET_JS_EVENT_CONNECT_COMPLETE,
|
|
|
|
NET_JS_EVENT_DISCONNECT,
|
2005-02-21 18:13:31 +01:00
|
|
|
NET_JS_EVENT_CLIENT_CONNECT,
|
|
|
|
NET_JS_EVENT_CLIENT_DISCONNECT,
|
2005-02-02 17:57:15 +01:00
|
|
|
NET_JS_EVENT_LAST
|
|
|
|
};
|
|
|
|
|
|
|
|
class CStartGameEvent: public CScriptEvent
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CStartGameEvent():
|
2005-04-22 09:12:55 +02:00
|
|
|
CScriptEvent(L"startGame", NET_JS_EVENT_START_GAME, false)
|
2005-02-02 17:57:15 +01:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
class CChatEvent: public CScriptEvent
|
|
|
|
{
|
|
|
|
CStrW m_Sender;
|
|
|
|
CStrW m_Message;
|
|
|
|
|
|
|
|
public:
|
2006-07-20 16:37:58 +02:00
|
|
|
CChatEvent(const CStrW& sender, const CStrW& message):
|
2005-04-22 09:12:55 +02:00
|
|
|
CScriptEvent(L"chat", NET_JS_EVENT_CHAT, false ),
|
2005-02-02 17:57:15 +01:00
|
|
|
m_Sender(sender),
|
|
|
|
m_Message(message)
|
|
|
|
{
|
2005-04-22 09:12:55 +02:00
|
|
|
AddLocalProperty(L"sender", &m_Sender, true);
|
|
|
|
AddLocalProperty(L"message", &m_Message, true);
|
2005-02-02 17:57:15 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class CConnectCompleteEvent: public CScriptEvent
|
|
|
|
{
|
|
|
|
CStrW m_Message;
|
|
|
|
bool m_Success;
|
|
|
|
|
|
|
|
public:
|
2006-07-20 16:37:58 +02:00
|
|
|
CConnectCompleteEvent(const CStrW& message, bool success):
|
2005-04-22 09:12:55 +02:00
|
|
|
CScriptEvent(L"connectComplete", NET_JS_EVENT_CONNECT_COMPLETE, false),
|
2005-02-02 17:57:15 +01:00
|
|
|
m_Message(message),
|
|
|
|
m_Success(success)
|
|
|
|
{
|
2005-04-22 09:12:55 +02:00
|
|
|
AddLocalProperty(L"message", &m_Message, true);
|
|
|
|
AddLocalProperty(L"success", &m_Success, true);
|
2005-02-02 17:57:15 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class CDisconnectEvent: public CScriptEvent
|
|
|
|
{
|
|
|
|
CStrW m_Message;
|
|
|
|
|
|
|
|
public:
|
2006-07-20 16:37:58 +02:00
|
|
|
CDisconnectEvent(const CStrW& message):
|
2005-04-22 09:12:55 +02:00
|
|
|
CScriptEvent(L"disconnect", NET_JS_EVENT_DISCONNECT, false),
|
2005-02-02 17:57:15 +01:00
|
|
|
m_Message(message)
|
|
|
|
{
|
2005-04-22 09:12:55 +02:00
|
|
|
AddLocalProperty(L"message", &m_Message, true);
|
2005-02-02 17:57:15 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2005-02-21 18:13:31 +01:00
|
|
|
class CClientConnectDisconnectCommon: public CScriptEvent
|
|
|
|
{
|
|
|
|
int m_SessionID;
|
|
|
|
CStrW m_Name;
|
|
|
|
CNetServerSession *m_pSession;
|
|
|
|
|
|
|
|
public:
|
2005-08-09 17:55:44 +02:00
|
|
|
CClientConnectDisconnectCommon(const wchar_t* UNUSED(eventName), int UNUSED(eventType),
|
2006-07-20 16:37:58 +02:00
|
|
|
int sessionID, const CStrW& name, CNetServerSession* pSession)
|
2005-08-09 17:55:44 +02:00
|
|
|
: CScriptEvent(L"clientConnect", NET_JS_EVENT_CLIENT_CONNECT, false),
|
2005-02-21 18:13:31 +01:00
|
|
|
m_SessionID(sessionID),
|
|
|
|
m_Name(name),
|
|
|
|
m_pSession(pSession)
|
|
|
|
{
|
2005-04-22 09:12:55 +02:00
|
|
|
AddLocalProperty(L"id", &m_SessionID, true);
|
|
|
|
AddLocalProperty(L"name", &m_Name, true);
|
2005-02-21 18:13:31 +01:00
|
|
|
if (m_pSession)
|
2005-04-22 09:12:55 +02:00
|
|
|
AddLocalProperty(L"session", &m_pSession, true);
|
2005-02-21 18:13:31 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CClientConnectEvent: public CClientConnectDisconnectCommon
|
|
|
|
{
|
2006-07-20 16:37:58 +02:00
|
|
|
CClientConnectEvent(int sessionID, const CStrW& name):
|
2005-02-21 18:13:31 +01:00
|
|
|
CClientConnectDisconnectCommon(
|
|
|
|
L"clientConnect",
|
|
|
|
NET_JS_EVENT_CLIENT_CONNECT,
|
|
|
|
sessionID,
|
|
|
|
name,
|
|
|
|
NULL)
|
|
|
|
{}
|
|
|
|
|
|
|
|
CClientConnectEvent(CNetServerSession *pSession):
|
|
|
|
CClientConnectDisconnectCommon(
|
|
|
|
L"clientConnect",
|
|
|
|
NET_JS_EVENT_CLIENT_CONNECT,
|
|
|
|
pSession->GetID(),
|
|
|
|
pSession->GetName(),
|
|
|
|
pSession)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CClientDisconnectEvent: public CClientConnectDisconnectCommon
|
|
|
|
{
|
2006-07-20 16:37:58 +02:00
|
|
|
CClientDisconnectEvent(int sessionID, const CStrW& name):
|
2005-02-21 18:13:31 +01:00
|
|
|
CClientConnectDisconnectCommon(
|
|
|
|
L"clientDisconnect",
|
|
|
|
NET_JS_EVENT_CLIENT_DISCONNECT,
|
|
|
|
sessionID,
|
|
|
|
name,
|
|
|
|
NULL)
|
|
|
|
{}
|
|
|
|
|
|
|
|
CClientDisconnectEvent(CNetServerSession *pSession):
|
|
|
|
CClientConnectDisconnectCommon(
|
|
|
|
L"clientDisconnect",
|
|
|
|
NET_JS_EVENT_CLIENT_DISCONNECT,
|
|
|
|
pSession->GetID(),
|
|
|
|
pSession->GetName(),
|
|
|
|
pSession)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2005-02-02 17:57:15 +01:00
|
|
|
#endif
|