Skocz do zawartości

  • Zaloguj korzystając z Facebooka Zaloguj korzystając z Twittera Zaloguj przez Steam Zaloguj poprzez Google      Logowanie »   
  • Rejestracja

Witamy w Nieoficjalnym polskim support'cie AMX Mod X

Witamy w Nieoficjalnym polskim support'cie AMX Mod X, jak w większości społeczności internetowych musisz się zarejestrować aby móc odpowiadać lub zakładać nowe tematy, ale nie bój się to jest prosty proces w którym wymagamy minimalnych informacji.

  • Rozpoczynaj nowe tematy i odpowiedaj na inne
  • Zapisz się do tematów i for, aby otrzymywać automatyczne uaktualnienia
  • Dodawaj wydarzenia do kalendarza społecznościowego
  • Stwórz swój własny profil i zdobywaj nowych znajomych
  • Zdobywaj nowe doświadczenia

Dołączona grafika Dołączona grafika

Guest Message by DevFuse
 

Zdjęcie

[forums.alliedmods.net] [DEV] WebSocket Server - Direct connection between webbrowser and gameserver


  • Nie możesz napisać tematu
  • Zaloguj się, aby dodać odpowiedź
Brak odpowiedzi do tego tematu

#1 Adminek AMXX.PL

    Admin :)

  • Bot

Reputacja: 156
Profesjonalista

  • Postów:7178
  • Lokalizacja:AMXX.PL
Offline

Napisano 12.04.2012 00:33

WebSocket
A WebSocket protocol implementation to create a direct connection between webbrowsers and gameservers.


WebSocket is a protocol designed to create a realtime connection between webbrowsers and webservers via javascript to exchange asynchronous information without reloading the page or requiring a client poll/page refresh.
This plugin provides an interface to create such an WebSocket server via SourceMod. Now you're able to do a live webchat seeing ingame events or even following the game in your browser like SourceTV or exchange whatever information you want.

This plugin doesn't open a server by itself and doesn't do much alone. It's a base for other plugins to implement fancy stuff without knowing the actual protocol.

Acknowledgements
This implementation follows the draft version 17 of the websocket protocol specifications, except:

  • No support for fragmented messages. (Would've been too much of a hassle, but could still be added, if really needed)
  • One websocket per plugin. Unlimited amount of connections though.
  • Multiple plugins opening a websocket on the same ip:port combo both share the WebSocket handle. The socket is only closed, if all plugins using it closed it. If one plugin closes the socket, the forwards are no longer fired, but the socket is still open until the last plugin closes it.
  • You can't use CloseHandle on websocket handles, since this is implemented in sourcepawn, which doesn't support adding "Handle" types. Use Websocket_Close instead.
  • You should always close your master websocket in OnPluginEnd().
  • This adapts to HTTP which is using TCP for connection management. You'll need to have the TCP port unblocked in your firewall to allow reading and writing.
Plugin Interface

Natives



PHP Code:

/**
* Creates a websocket server which listens on the supplied ip:port combination.
*
* @param sHostName The IP to bind to.
* @param iPort The port to listen on
* @param inc The incoming child connection callback
* @param we The error callback
* @return A WebsocketHandle or INVALID_WEBSOCKET_HANDLE on error.
*/
native WebsocketHandle:Websocket_Open(const String:sHostName[], iPort, WebsocketIncomingCB:inc, WebsocketErrorCB:we, WebsocketCloseCB:clo);

/**
* Hooks child socket's events
*
* @param childwebsocket The child websocket to hook.
* @param recv Data receive callback
* @param disc The disconnect callback
* @param we The error callback
* @return True if child socket was hooked, false otherwise
*/
native bool:Websocket_HookChild(WebsocketHandle:childwebsocket, WebsocketReceiveCB:recv, WebsocketDisconnectCB:disc, WebsocketErrorCB:we);


/**
* Sends text or binary data through the websocket
*
* @param childwebsocket The child websocket to send to
* @param type The datatype SendType_Text or SendType_Binary
* @param sPayLoad The data to send
* @param dataSize If set, it's used as maxlength. Useful for binary data where might be used before the end of the data.
* @return True if child socket was hooked, false otherwise
*/
native bool:Websocket_Send(WebsocketHandle:childwebsocket, WebsocketSendType:type, const String:sPayload[], const dataSize=-1);

/**
* Gets a child websocket's readyState.
*
* @param childwebsocket The child websocket
* @return The readyState
*/
native WebsocketReadyState:Websocket_GetReadyState(WebsocketHandle:childwebsocket);

/**
* Unhooks a child socket's events: If there's no plugin listening anymore, the socket is closed.
*
* @param childwebsocket The child websocket
* @noreturn
*/
native Websocket_UnhookChild(WebsocketHandle:childwebsocket);

/**
* Closes a listening master socket, created with Websocket_Open.
* Note: The socket will still be open, if there are more plugins using it.
*
* Call this in OnPluginEnd()!
*
* @param websocket The master websocket
* @noreturn
*/
native Websocket_Close(WebsocketHandle:websocket);

Requirements
Compiling dependencies
Thanks to
  • sfPlayer and his Socket extenstion
  • SirLamer - Base64 include
Server owners only need the websocket.smx in their plugins folder and the Socket extension installed. This plugin won't compile on the forum due to it's custom include requirements.



Attached Files Dołączona grafika Get Plugin or Get Source (websocket.sp - 35.1 KB) Dołączona grafika websocket.smx (17.6 KB) Dołączona grafika websocket.inc (5.2 KB)

Wyświetl pełny artykuł




Użytkownicy przeglądający ten temat: 0

0 użytkowników, 0 gości, 0 anonimowych