⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 server_8h-source.html

📁 用来介绍ZIG Library游戏网络引擎的文档
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>server.h Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.2.18 --><center><a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; </center><hr><h1>server.h</h1><div class="fragment"><pre>00001 <span class="comment">/*</span>00002 <span class="comment">    ZIG - An extendable, portable game engine focused on networking &amp; scripting</span>00003 <span class="comment">    Project Home: http://zige.sourceforge.net</span>00004 <span class="comment">    Copyright (C) 2002  F醔io Reis Cecin &lt;fcecin AT inf DOT ufrgs DOT br&gt;</span>00005 <span class="comment"></span>00006 <span class="comment">    This library is free software; you can redistribute it and/or</span>00007 <span class="comment">    modify it under the terms of the GNU Lesser General Public</span>00008 <span class="comment">    License as published by the Free Software Foundation; either</span>00009 <span class="comment">    version 2.1 of the License, or (at your option) any later version.</span>00010 <span class="comment"></span>00011 <span class="comment">    This library is distributed in the hope that it will be useful,</span>00012 <span class="comment">    but WITHOUT ANY WARRANTY; without even the implied warranty of</span>00013 <span class="comment">    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</span>00014 <span class="comment">    Lesser General Public License for more details.</span>00015 <span class="comment"></span>00016 <span class="comment">    You should have received a copy of the GNU Lesser General Public</span>00017 <span class="comment">    License along with this library; if not, write to the Free Software</span>00018 <span class="comment">    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   </span>00019 <span class="comment">*/</span>00020 <span class="comment">/*</span>00021 <span class="comment"></span>00022 <span class="comment">        LEETNET 2</span>00023 <span class="comment"></span>00024 <span class="comment">        net server</span>00025 <span class="comment"></span>00026 <span class="comment">*/</span>00027 00028 <span class="preprocessor">#ifndef _ZIG_HEADER_SERVER_H_</span>00029 <span class="preprocessor"></span><span class="preprocessor">#define _ZIG_HEADER_SERVER_H_</span>00030 <span class="preprocessor"></span>00031 <span class="preprocessor">#ifndef NO_DOXYGEN              // internal class -- do not document</span>00032 <span class="preprocessor"></span>00033 <span class="preprocessor">#include "leetnet.h"</span>00034 <span class="preprocessor">#include "leet.h"</span>00035 <span class="preprocessor">#include "station.h"</span>00036 <span class="preprocessor">#include "thread.h"</span>00037 00038 <span class="preprocessor">#include &lt;nl.h&gt;</span>00039 <span class="preprocessor">#include "buffer.h"</span>00040 <span class="preprocessor">#include "channel.h"</span>00041 00042 <span class="preprocessor">#include &lt;map&gt;</span>00043 <span class="preprocessor">#include &lt;string&gt;</span>00044 <span class="comment">//using namespace std;</span>00045 00046 <span class="comment">// hardcoded client limit - client id's will always be assigned between ( 0 .. LIMIT-1 )</span>00047 <span class="preprocessor">#define HARDCODED_CLIENT_LIMIT 65536</span>00048 <span class="preprocessor"></span>00049 <span class="comment">// server behavior abstract class (interface)</span>00050 <span class="comment">// you must subclass this, and pass an instance to the server_c instance (replacement for stinky callbacks)</span>00051 <span class="keyword">class </span>server_behavior_i {00052 <span class="keyword">public</span>:00053 00054         <span class="comment">// implement this so the leetserver knows if it should accept or deny a connection</span>00055         <span class="comment">// this can be used for a first quick authentication over the IP address of the client or, more commonly, </span>00056         <span class="comment">// to deny connections if the server is full or if the server is "locked" or something like that...</span>00057         <span class="comment">// parameter "custom": custom connect data passed by the client (contains credentials maybe..?)</span>00058         <span class="comment">// parameter "answer": an empty buffer, to be filled by the behavior with data to be answered to</span>00059         <span class="comment">// the client. if the client is rejected and custom.code == 1, no answer packet will be sent (silent rejection)</span>00060         <span class="keyword">virtual</span> <span class="keywordtype">bool</span> leet_accept_client(NLaddress &amp;client_addr, <a class="code" href="classbuffer__c.html">buffer_c</a> &amp;custom, <a class="code" href="classbuffer__c.html">buffer_c</a> &amp;answer) = 0;00061 00062         <span class="comment">// leetserver callback: a client has just been accepted by (connected to) the leetserver. </span>00063         <span class="comment">// client_id: the unique network identity of this connected client</span>00064         <span class="comment">// custom: the same "custom connect data" that was passed to leet_accept_client() for this </span>00065         <span class="comment">//  same client. (see above) </span>00066         <span class="keyword">virtual</span> <span class="keywordtype">void</span> leet_client_connected(<span class="keywordtype">int</span> client_id, <a class="code" href="classbuffer__c.html">buffer_c</a> &amp;custom) = 0;00067 00068         <span class="comment">// leetserver callback: a client has just disconnected or been disconnected by the leetserver</span>00069         <span class="comment">// "code_reason": 0 if no special reason, nonzero otherwise (currenly only the negative-value </span>00070         <span class="comment">// error codes from station_c::send_packet() are propagated (as-is) through code_reason, but </span>00071         <span class="comment">// other values might be used in the future too)</span>00072         <span class="keyword">virtual</span> <span class="keywordtype">void</span> leet_client_disconnected(<span class="keywordtype">int</span> client_id, <span class="keywordtype">int</span> code_reason) = 0;00073 00074         <span class="comment">// leetserver callback: incoming game packet from client</span>00075         <span class="keyword">virtual</span> <span class="keywordtype">void</span> leet_client_incoming_data(<span class="keywordtype">int</span> client_id, <a class="code" href="classbuffer__c.html">buffer_c</a> &amp;in, <span class="keywordtype">int</span> packet_id) = 0;00076 00077         <span class="comment">// leetserver callback: somebody wants to get some server information (LEET_SERVERINFO message to</span>00078         <span class="comment">// the server's public UDP requests port). remote_addr is the address of where the request came from.</span>00079         <span class="comment">// "custom" contains extra request information that was on the request packet (may be empty).</span>00080         <span class="comment">// "answer" is the buffer where the callback must write the answer to give to the client (it's already</span>00081         <span class="comment">// empty). return false if should not answer anything (ignore it), return true to return the "answer".</span>00082         <span class="keyword">virtual</span> <span class="keywordtype">bool</span> leet_get_server_info(NLaddress &amp;remote_addr, <a class="code" href="classbuffer__c.html">buffer_c</a> &amp;custom, <a class="code" href="classbuffer__c.html">buffer_c</a> &amp;answer) = 0;00083 00084         <span class="comment">// leetserver callback: a channel to a certain client has been opened.</span>00085         <span class="keyword">virtual</span> <span class="keywordtype">void</span> leet_channel_opened(<span class="keywordtype">int</span> client_id, <span class="keywordtype">int</span> channel_id, <a class="code" href="classchannel__c.html">channel_c</a> *ch) = 0;00086 00087         <span class="comment">// leetserver callback: a channel to a certain client could not be opened</span>00088         <span class="comment">// error: an error code.</span>00089         <span class="keyword">virtual</span> <span class="keywordtype">void</span> leet_channel_open_failed(<span class="keywordtype">int</span> client_id, <span class="keywordtype">int</span> channel_id, <span class="keywordtype">int</span> failcode) = 0;00090 };00091 00092 <span class="comment">// remoteclient class: represents a view from the server side of one remote client</span>00093 <span class="keyword">class </span>server_c;00094 <span class="keyword">class </span>remote_client_c {00095 <span class="keyword">public</span>:00096 00097         <span class="comment">//reference to owner server</span>00098         server_c *server;00099 00100         <span class="comment">//client's id (map key in server_c::clients)</span>00101         <span class="keywordtype">int</span> id;00102         00103         <span class="comment">//client's remote address</span>00104         NLaddress       remote_addr;00105         00106         <span class="comment">//rudp socket</span>00107         station_c       station;00108         00109         <span class="comment">//client's channel port so the server can connect to it</span>00110         NLushort channel_port;00111 00112         <span class="comment">//thread blocked on reading from client</span>00113         thread_c&lt;server_c&gt; reader_thread;00114         <span class="keywordtype">bool</span> reader_thread_quit;                <span class="comment">//flag for thread knowing that it should('nt) quit yet</span>00115 00116         <span class="comment">// the variables below encode the client's connection state</span>00117         <span class="comment">//</span>00118         <span class="keyword">volatile</span> <span class="keywordtype">bool</span>           told_disconnect;                <span class="comment">// client already told that he wants to disconnect or, a "disconnect"</span>00119                                                                                                                                                         <span class="comment">// packet was already received from the client</span>00120         <span class="keyword">volatile</span> <span class="keywordtype">bool</span>           server_disconnected; <span class="comment">// set to true when the server kicks the client. told_disconnect may</span>00121                                                                                                                                                          <span class="comment">// be false at that point.</span>00122 00123         <span class="comment">//a server_c::disconnect_client() method is running on a thread or has already been called</span>00124         <span class="comment">//for this client.</span>00125         <span class="keyword">volatile</span> <span class="keywordtype">bool</span>           disconnect_client;00126 00127         <span class="comment">// for the new "asynchronous disconnection" routine (when using ZIG_SERVER_THREADING_0)</span>00128         <span class="comment">// time to send next disconnect packet</span>00129         <span class="keywordtype">double</span> disconnect_packets_next_time;00130 00131         <span class="comment">// count of disconnection packets left to send</span>00132         <span class="keywordtype">int</span> disconnect_packets_left_count;00133 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -