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

📄 client_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>client.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>client.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 client</span>00025 <span class="comment"></span>00026 <span class="comment">*/</span>00027 00028 <span class="preprocessor">#ifndef _ZIG_HEADER_CLIENT_H_</span>00029 <span class="preprocessor"></span><span class="preprocessor">#define _ZIG_HEADER_CLIENT_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 "console.h"</span>00037 <span class="preprocessor">#include "channel.h"</span>00038 <span class="preprocessor">#include "thread.h"</span>00039 <span class="preprocessor">#include "address.h"</span>00040 00041 <span class="preprocessor">#include &lt;list&gt;</span>00042 00043 <span class="comment">//NEW v1.3.0: values for internal_disconnected_code_reason (NOT sent to disconnect() to avoid mixing up</span>00044 <span class="comment">// with app client's codes)</span>00045 <span class="keyword">enum</span> {00046 00047         <span class="comment">// IMPORTANT: negative values are reserved for station_c::send_packet() error codes !!! (-1, -2, -3, -4, ...)</span>00048 00049         <span class="comment">// default reason code, meaning nothing. DON'T CHANGE THIS VALUE.</span>00050         LEETCLIENT_DISCONNECTED = 0,      00051 00052         <span class="comment">//disconnected by a socket error in the reader thread</span>00053         LEETCLIENT_DISCONNECTED_SOCKET_ERROR,00054 00055         <span class="comment">//disc. because leet client couldn't parse a message from leet server</span>00056         LEETCLIENT_DISCONNECTED_PROTOCOL_VIOLATION,00057 };00058 00059 <span class="comment">//helper class</span>00060 <span class="keyword">class </span>serverinfo_result_c {00061 <span class="keyword">public</span>:00062         <a class="code" href="classaddress__c.html">address_c</a> addr;00063         <a class="code" href="classbuffer__c.html">buffer_c</a> info;00064         <span class="keywordtype">int</span> time_ms;00065 };00066 00067 <span class="comment">//client behavior (replacement for callbacks)</span>00068 <span class="keyword">class </span>client_behavior_i {00069 <span class="keyword">public</span>:00070 00071         <span class="comment">//client has connected sucessfully, custom accept packet data passed</span>00072         <span class="keyword">virtual</span> <span class="keywordtype">void</span> leet_connected(<a class="code" href="classbuffer__c.html">buffer_c</a> &amp;hello) = 0;00073 00074         <span class="comment">//connection attempt timed out</span>00075         <span class="keyword">virtual</span> <span class="keywordtype">void</span> leet_connection_timed_out() = 0;00076 00077         <span class="comment">//connection refused, custom reason data passed from the server.</span>00078         <span class="keyword">virtual</span> <span class="keywordtype">void</span> leet_connection_refused(<a class="code" href="classbuffer__c.html">buffer_c</a> &amp;reason) = 0;00079 00080         <span class="comment">//client has been disconnected. if disconnection was initiated by the server, then server_initiated</span>00081         <span class="comment">//will be == true, and "reason" may contain custom disconnect data passed by the server (or not).</span>00082         <span class="comment">//if disconnection was client-initiated, then "reason" is alwats empty.</span>00083         <span class="comment">//code_reason is a custom integer passed to connect(false, ...);</span>00084         <span class="comment">//internal_reason is one of the LEET_DISCONNECTED_xxx values, where 0 means "no special reason"</span>00085         <span class="keyword">virtual</span> <span class="keywordtype">void</span> leet_disconnected(<span class="keywordtype">bool</span> server_initiated, <a class="code" href="classbuffer__c.html">buffer_c</a> &amp;reason, <span class="keywordtype">int</span> code_reason, <span class="keywordtype">int</span> internal_reason) = 0;00086 00087         <span class="comment">//incoming data from server! passes the data and the packet id (may be of interest)</span>00088         <span class="keyword">virtual</span> <span class="keywordtype">void</span> leet_incoming_data(<a class="code" href="classbuffer__c.html">buffer_c</a> &amp;in, <span class="keywordtype">int</span> packet_id) = 0;00089 00090         <span class="comment">//incoming serverinfo result. time_ms: time in milliseconds between request and response.</span>00091         <span class="comment">// RETURN VALUE: if info.code == 1, then the request TIMED OUT. if info.code == 0, request answered ok.</span>00092         <span class="keyword">virtual</span> <span class="keywordtype">void</span> leet_incoming_server_info(<a class="code" href="classaddress__c.html">address_c</a> &amp;addr, <a class="code" href="classbuffer__c.html">buffer_c</a> &amp;info, <span class="keywordtype">int</span> time_ms) = 0;00093 00094         <span class="comment">// leetserver callback: a channel to the server has been opened.</span>00095         <span class="keyword">virtual</span> <span class="keywordtype">void</span> leet_channel_opened(<span class="keywordtype">int</span> channel_id, <a class="code" href="classchannel__c.html">channel_c</a> *ch) = 0;00096 00097         <span class="comment">// incoming request from server_c (using it for the ziglet-sync stuff)</span>00098         <span class="keyword">virtual</span> <span class="keywordtype">void</span> leet_incoming_request(<span class="keywordtype">int</span> request_id, <a class="code" href="classbuffer__c.html">buffer_c</a> &amp;in) = 0;00099 };00100 00101 <span class="comment">//possible values for client_c's int connect_state var.</span>00102 <span class="keyword">enum</span> {00103 00104         CCS_NOT_CONNECTED,                                              <span class="comment">//client is not connected</span>00105         CCS_TRYING_DISCONNECTION,                       <span class="comment">//client is connected, trying disconnection</span>00106         CCS_ENDING_DISCONNECTION,                       <span class="comment">//after trying disconnection, when received an STC_DISCONNECT from server, but still not disconnected</span>00107         CCS_TRYING_CONNECTION,                          <span class="comment">//client is disconnected, trying connection</span>00108         CCS_CONNECTED                                                           <span class="comment">//client is connected</span>00109 };00110 00111 <span class="comment">//leetnet2 client class</span>00112 <span class="keyword">class </span>client_c : <span class="keyword">public</span> leet_c, <span class="keyword">public</span> station_callback_i {00113 <span class="keyword">public</span>:00114 00115         <span class="comment">//ctor, setting behavior. behavior will **NOT** be deleted by the client's destructor!</span>00116         <span class="comment">//NEW (ZIG v1.2.1): parameter to enable or disable the socket polling mode</span>00117         client_c(client_behavior_i *beh, <span class="keywordtype">bool</span> enable_socket_polling, <a class="code" href="classconsole__c.html">console_c</a> *conio = 0, <span class="keywordtype">int</span> threads_prio = <a class="code" href="zig_8h.html#a25a13">ZIGTHREADSPRIO_NET_HIGH</a>);00118 00119         <span class="comment">//dtor</span>00120         <span class="keyword">virtual</span> ~client_c();

⌨️ 快捷键说明

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