• 大小: 6.82MB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2023-10-14
  • 语言: C/C++
  • 标签: 冒险岛  

资源简介

冒险岛 c++ 服务端源码,是学习网络游戏编程的好资料,有完整的数据结构。

资源截图

代码片段和文件信息

 /*This file is part of TitanMS.

    TitanMS 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 3 of the License or
    (at your option) any later version.

    TitanMS 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 TitanMS.  If not see .*/

#include 
#include 
#include “Acceptor.h“
#include “PacketHandler.h“

Acceptor::Acceptor(int port Selector* selector AbstractPlayerFactory* apf bool master) {
abstractPlayerFactory = apf;

SOCKET acceptSocket = socket (AF_INET SOCK_STREAM IPPROTO_TCP);
if (acceptSocket == INVALID_SOCKET) {
printf (“socket error: %d\n“ WSAGetLastError());
return;
}

sockaddr_in service;
service.sin_family = AF_INET;
service.sin_addr.s_addr = INADDR_ANY; //inet_addr(“127.0.0.1“);
service.sin_port = htons(port);

if (bind( acceptSocket (SOCKADDR*) &service sizeof(service)) == SOCKET_ERROR) {
printf(“bind() error: %d\n“ WSAGetLastError());
return;
}

if (listen( acceptSocket 10 ) == SOCKET_ERROR) {
printf(“listen() error: %d\n“ WSAGetLastError());
closesocket(acceptSocket);
return;
}

this->master = master;

selector->registerSocket (acceptSocket true false true this);

}

void Acceptor::handle (Selector* selector int socket) {
SOCKET sock = accept( socket NULL NULL );
printf (“accept\n“);
if (sock == INVALID_SOCKET) {
printf(“accept error: %d\n“ WSAGetLastError());
return;
}

AbstractPlayer* player = abstractPlayerFactory->createPlayer();
PacketHandler* ph;
if(master)
ph = new PacketHandlerMaster(sock player);
else
ph = new PacketHandlerMaple(sock player);
player->setPacketHandler(ph);
selector->registerSocket (sock true false true ph);
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2013-11-04 04:43  MapleStory_tms-master\
     文件         483  2013-11-04 04:43  MapleStory_tms-master\.gitattributes
     文件        2643  2013-11-04 04:43  MapleStory_tms-master\.gitignore
     目录           0  2013-11-04 04:43  MapleStory_tms-master\Connection\
     文件        1114  2013-11-04 04:43  MapleStory_tms-master\Connection\AbstractPlayer.h
     文件        2107  2013-11-04 04:43  MapleStory_tms-master\Connection\Acceptor.cpp
     文件        1051  2013-11-04 04:43  MapleStory_tms-master\Connection\Acceptor.h
     文件        3818  2013-11-04 04:43  MapleStory_tms-master\Connection\Connection.vcproj
     文件        5197  2013-11-04 04:43  MapleStory_tms-master\Connection\Connection.vcxproj
     文件        1696  2013-11-04 04:43  MapleStory_tms-master\Connection\Connection.vcxproj.filters
     文件        2742  2013-11-04 04:43  MapleStory_tms-master\Connection\Connector.cpp
     文件        1073  2013-11-04 04:43  MapleStory_tms-master\Connection\Connector.h
     文件        3749  2013-11-04 04:43  MapleStory_tms-master\Connection\PacketHandler.cpp
     文件        1733  2013-11-04 04:43  MapleStory_tms-master\Connection\PacketHandler.h
     文件        2514  2013-11-04 04:43  MapleStory_tms-master\Connection\Selector.cpp
     文件        1272  2013-11-04 04:43  MapleStory_tms-master\Connection\Selector.h
     目录           0  2013-11-04 04:43  MapleStory_tms-master\Decoder\
     文件       14422  2013-11-04 04:43  MapleStory_tms-master\Decoder\AESEncryption.cpp
     文件         123  2013-11-04 04:43  MapleStory_tms-master\Decoder\AESEncryption.h
     文件        1377  2013-11-04 04:43  MapleStory_tms-master\Decoder\Decoder.cbp
     文件        1616  2013-11-04 04:43  MapleStory_tms-master\Decoder\Decoder.cpp
     文件        1667  2013-11-04 04:43  MapleStory_tms-master\Decoder\Decoder.h
     文件         251  2013-11-04 04:43  MapleStory_tms-master\Decoder\Decoder.layout
     文件        3478  2013-11-04 04:43  MapleStory_tms-master\Decoder\Decoder.vcproj
     文件        4590  2013-11-04 04:43  MapleStory_tms-master\Decoder\Decoder.vcxproj
     文件        1547  2013-11-04 04:43  MapleStory_tms-master\Decoder\Decoder.vcxproj.filters
     文件        4480  2013-11-04 04:43  MapleStory_tms-master\Decoder\MapleEncryption.cpp
     文件        1023  2013-11-04 04:43  MapleStory_tms-master\Decoder\MapleEncryption.h
     文件        1078  2013-11-04 04:43  MapleStory_tms-master\Decoder\MasterDecoder.cpp
     文件        1207  2013-11-04 04:43  MapleStory_tms-master\Decoder\MasterDecoder.h
     文件        1812  2013-11-04 04:43  MapleStory_tms-master\MapleStoryServer.sln
............此处省略10313个文件信息

评论

共有 条评论