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

📄 station_8h-source.html

📁 用来介绍ZIG Library游戏网络引擎的文档
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<!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>station.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>station.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">        reliable UDP socket+brains</span>00025 <span class="comment"></span>00026 <span class="comment">*/</span>00027 00028 <span class="preprocessor">#ifndef _ZIG_HEADER_STATION_H_</span>00029 <span class="preprocessor"></span><span class="preprocessor">#define _ZIG_HEADER_STATION_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 &lt;nl.h&gt;</span>00034 <span class="preprocessor">#include &lt;hawkthreads.h&gt;</span>00035 <span class="preprocessor">#include "leetnet.h"</span>00036 <span class="preprocessor">#include "buffer.h"</span>00037 <span class="preprocessor">#include "console.h"</span>00038 <span class="preprocessor">#include "<a class="code" href="utils_8h.html">utils.h</a>"</span>00039 <span class="preprocessor">#include "thread.h"</span>00040 <span class="preprocessor">#include "channel.h"</span>00041 <span class="preprocessor">#include "listensocket.h"</span>00042 00043 <span class="preprocessor">#include "<a class="code" href="zig_8h.html">zig.h</a>"</span>  <span class="comment">//v1.3.0: RSP_* enum moved to zig.h since it is used by ZIG API clients</span>00044 00045 <span class="comment">//possible return codes for send_packet():  (added in v1.3.0)</span>00046 <span class="preprocessor">#define SENDPACKET_OK                     0    // no error</span>00047 <span class="preprocessor"></span><span class="preprocessor">#define SENDPACKET_SOCKET_ERROR          -1    // when nlWrite() returns NL_INVALID</span>00048 <span class="preprocessor"></span><span class="preprocessor">#define SENDPACKET_CRITICAL_OVERFLOW     -2    // protocol limitation: excess of pending outbound critical messages</span>00049 <span class="preprocessor"></span><span class="preprocessor">#define SENDPACKET_ACKDELTA_OVERFLOW     -3    // protocol limitation: "jump" between two outbound ack IDs encoded is greater than -128/+127</span>00050 <span class="preprocessor"></span><span class="preprocessor">#define SENDPACKET_RELDELTA_OVERFLOW     -4    // protocol limitation: "jump" between two outbound reliable message IDs encoded is greater than -128/+127</span>00051 <span class="preprocessor"></span>00052 <span class="comment">// for debug: places a single mutex around ALL of station_c's state/methods aiming for</span>00053 <span class="comment">// absolute thread-safety (but some stuff might stop working and deadlock)</span>00054 <span class="comment">//#define STATION_MAX_SYNCHRONIZATION</span>00055 00056 <span class="preprocessor">#ifdef STATION_MAX_SYNCHRONIZATION</span>00057 <span class="preprocessor"></span><span class="preprocessor">#define STATION_LOCK max_mutex.lock();</span>00058 <span class="preprocessor"></span><span class="preprocessor">#define STATION_UNLOCK max_mutex.unlock();</span>00059 <span class="preprocessor"></span><span class="preprocessor">#else</span>00060 <span class="preprocessor"></span><span class="preprocessor">#define STATION_LOCK  </span>00061 <span class="preprocessor"></span><span class="preprocessor">#define STATION_UNLOCK  </span>00062 <span class="preprocessor"></span><span class="preprocessor">#endif</span>00063 <span class="preprocessor"></span>00064 00065 <span class="comment">//make_request() codes: </span>00066 <span class="comment">//  requests / responses through an ESTABILISHED connection between two stations.</span>00067 <span class="comment">//</span>00068 <span class="comment">//==&gt; the first byte of the request is used by the station to identify requests and</span>00069 <span class="comment">//    responses for itself (0==itself, 1=user client_c/server_c). the codes below are</span>00070 <span class="comment">//    for station internal communication</span>00071 <span class="comment">//</span>00072 <span class="keyword">enum</span> {00073 00074         LEETST_REQUEST_NOP = 0,00075         LEETST_REQUEST_MTS_TCPCONNECT  <span class="comment">//master requests slave to connect to it's TCP listening socket</span>00076 };00077 00078 <span class="comment">//first byte of a REQUEST/RESPONSE</span>00079 <span class="preprocessor">#define                 STATION_REQRESP_INTERNAL                (NLubyte)0</span>00080 <span class="preprocessor"></span><span class="preprocessor">#define                 STATION_REQRESP_USER                            (NLubyte)1</span>00081 <span class="preprocessor"></span>00083 <span class="keyword">class </span>station_callback_i {00084 <span class="keyword">public</span>:00085 00087         <span class="keyword">virtual</span> <span class="keywordtype">void</span> station_channel_opened(<span class="keywordtype">int</span> channel_id, <a class="code" href="classchannel__c.html">channel_c</a> *ch, <span class="keywordtype">int</span> tag) = 0;00088 00090         <span class="keyword">virtual</span> <span class="keywordtype">void</span> station_channel_failed(<span class="keywordtype">int</span> channel_id, <span class="keywordtype">int</span> code_reason, <span class="keywordtype">int</span> tag) = 0;00091 };00092 00093 <span class="preprocessor">#include &lt;map&gt;</span>00094 <span class="preprocessor">#include &lt;vector&gt;</span>00095 <span class="preprocessor">#include &lt;deque&gt;</span>00096 <span class="comment">//using namespace std;</span>00097 00098 <span class="preprocessor">#define         MAX_INCOMING_MESSAGES           256                     </span>00099 <span class="preprocessor"></span>00100 <span class="preprocessor"></span><span class="comment">// v1.3.0: not needed anymore - all buffers auto-resize as needed</span>00101 <span class="comment">//#define               BIG_UDP_BUFFER_SIZE                     8192</span>00102 00103 <span class="comment">//special packet ids. since "valid" packet ids are from 1 to 65280, there's a lot of packet ids</span>00104 <span class="comment">// to use in 65281 to 65535...</span>00105 <span class="comment">//also, id == 0 means a "special" packet (unreliable data passed directly to the application)</span>00106 <span class="comment">//#define   STATION_REQUEST_PACKET_ID    65534          //first ushort of a request packet</span>00107 <span class="comment">//#define   STATION_RESPONSE_PACKET_ID   65535          //first ushort of a response packet</span>00108 <span class="comment">//</span>00109 <span class="comment">//  NEW: the "unused" range of ushort IDs is now 32513 to 32767 since we changed</span>00110 <span class="comment">//    ushort to 1..32512 (32512: the largest 15-bit unsigned value that is still divisible by</span>00111 <span class="comment">//    256 (MAX_INCOMING_MESSAGES))</span>00112 <span class="comment">//</span>00113 <span class="preprocessor">#define   STATION_REQUEST_PACKET_ID      32766  //first ushort of a request packet</span>00114 <span class="preprocessor"></span><span class="preprocessor">#define   STATION_RESPONSE_PACKET_ID     32767  //first ushort of a response packet</span>00115 <span class="preprocessor"></span>00116 <span class="preprocessor">#define   STATION_COMPRESSED_PACKET_BIT  32768  //flag smuggled on the "ID ushort" tells if packet is compressed or not</span>00117 <span class="preprocessor"></span>00118 <span class="preprocessor">#define         REQUEST_DISCARD_RESPONSE                (buffer_c*)0xFFFFFFFF</span>00119 <span class="preprocessor"></span>00120 <span class="preprocessor">#define         RESPONSE_WAITING_CODE                           0               //for "resps" .code  field</span>00121 <span class="preprocessor"></span><span class="preprocessor">#define         RESPONSE_ARRIVED_CODE                           1</span>00122 <span class="preprocessor"></span>00123 <span class="preprocessor">#define   ANSWER_PENDING_ID           0         //for "answs" .id  field</span>00124 <span class="preprocessor"></span><span class="preprocessor">#define   ANSWER_GIVEN_ID             1</span>00125 <span class="preprocessor"></span>00126 <span class="preprocessor">#define   READ_PACKET_INTERNAL        -2  //returned by read_packet() when the read packet was "consumed" internally by the station</span>00127 <span class="preprocessor"></span>                                          <span class="comment">// **** MUST BE DIFFERENT FROM NL_INVALID!! (-1) ****</span>00128 00129 <span class="comment">//enum: buffer codes for process_incoming_packet()</span>00130 <span class="keyword">enum</span> {00131 00132         STATION_INCOMING_PACKET_NORMAL   = 0,           <span class="comment">//regular game packet (id, acks, reliables....)</span>00133         STATION_INCOMING_PACKET_SPECIAL  = 1,           <span class="comment">//special packet (id==0 and a custom chunk)</span>00134         STATION_INCOMING_PACKET_REQUEST  = 2            <span class="comment">//request packet (id==STATION_REQUEST_PACKET ID + request id + request chunk)</span>00135 };00136 00137 <span class="comment">//an outgoing message in the queue</span>00138 <span class="keyword">class </span>omsg_c {00139 <span class="keyword">public</span>:00140         <span class="keywordtype">int</span> id;                 <span class="comment">//the message id</span>

⌨️ 快捷键说明

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