Commit dbeeeac5 authored by argon.sun's avatar argon.sun

fix

parent 3931d638
......@@ -42,7 +42,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
mainGame->ebStartLP->setText(L"5");
if(_wtoi(mainGame->ebDrawCount->getText()) == 0)
mainGame->ebStartLP->setText(L"1");
if(mainGame->netManager.CreateHost()) {
if(mainGame->netManager.CreateHost(mainGame->cbIPList->getSelected())) {
mainGame->btnLanStartServer->setEnabled(false);
mainGame->btnLanCancelServer->setEnabled(true);
mainGame->btnLanConnect->setEnabled(false);
......@@ -59,7 +59,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
break;
}
case BUTTON_LAN_REFRESH: {
if(mainGame->netManager.RefreshHost()) {
if(mainGame->netManager.RefreshHost(mainGame->cbIPList->getSelected())) {
mainGame->btnLanStartServer->setEnabled(false);
mainGame->btnLanConnect->setEnabled(false);
mainGame->btnRefreshList->setEnabled(false);
......@@ -813,7 +813,7 @@ bool ClientField::OnEvent(const irr::SEvent& event) {
if(mainGame->wModes->getActiveTab() == 1) {
if(mainGame->is_refreshing || mainGame->netManager.is_creating_host)
break;
if(mainGame->netManager.RefreshHost()) {
if(mainGame->netManager.RefreshHost(mainGame->cbIPList->getSelected())) {
mainGame->btnLanStartServer->setEnabled(false);
mainGame->btnLanConnect->setEnabled(false);
mainGame->btnRefreshList->setEnabled(false);
......
......@@ -38,7 +38,7 @@ bool Game::Initialize() {
dField.device = device;
deckBuilder.device = device;
memset(&dInfo, 0, sizeof(DuelInfo));
netManager.local_addr = NetManager::GetLocalAddress();
netManager.GetLocalAddress();
netManager.send_buffer_ptr = &netManager.send_buf[2];
deckManager.LoadLFList();
driver = device->getVideoDriver();
......@@ -52,8 +52,7 @@ bool Game::Initialize() {
smgr = device->getSceneManager();
device->setWindowCaption(L"[---]");
device->setResizable(false);
myswprintf(dataManager.strBuffer, L"模式选择(当前IP:%d.%d.%d.%d 版本:0x%X)", netManager.local_addr & 0xff, (netManager.local_addr >> 8) & 0xff,
(netManager.local_addr >> 16) & 0xff, (netManager.local_addr >> 24) & 0xff, PROTO_VERSION);
myswprintf(dataManager.strBuffer, L"YGOPro Version:0x%X)", PROTO_VERSION);
wModeSelection = env->addWindow(rect<s32>(270, 100, 750, 490), false, dataManager.strBuffer);
wModeSelection->getCloseButton()->setVisible(false);
wModes = env->addTabControl(rect<s32>(5, 60, 475, 350), wModeSelection, false, true, TAB_MODES);
......@@ -119,13 +118,23 @@ bool Game::Initialize() {
lstReplayList->setItemHeight(18);
btnLoadReplay = env->addButton(rect<s32>(180, 200, 280, 225), tabReplay, BUTTON_LOAD_REPLAY, L"载入录像");
env->addStaticText(L"昵称:", rect<s32>(10, 30, 90, 50), false, false, wModeSelection);
ebUsername = env->addEditBox(L"", rect<s32>(80, 25, 260, 50), true, wModeSelection);
ebUsername = env->addEditBox(L"", rect<s32>(80, 25, 240, 50), true, wModeSelection);
ebUsername->setTextAlignment(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER);
env->addStaticText(L"卡组:", rect<s32>(270, 30, 350, 50), false, false, wModeSelection);
cbDeckSel = env->addComboBox(rect<s32>(320, 25, 470, 50), wModeSelection, -1);
env->addStaticText(L"卡组:", rect<s32>(250, 30, 350, 50), false, false, wModeSelection);
cbDeckSel = env->addComboBox(rect<s32>(310, 25, 410, 50), wModeSelection, -1);
RefreshDeck(cbDeckSel);
btnDeckEdit = env->addButton(rect<s32>(410, 55, 470, 80), wModeSelection, BUTTON_DECK_EDIT, L"编辑");
btnDeckEdit = env->addButton(rect<s32>(420, 25, 470, 50), wModeSelection, BUTTON_DECK_EDIT, L"编辑");
stModeStatus = env->addStaticText(L"", rect<s32>(20, 360, 350, 380), false, false, wModeSelection);
env->addStaticText(L"IP选择:", rect<s32>(250, 55, 350, 80), false, false, wModeSelection);
cbIPList = env->addComboBox(rect<s32>(310, 55, 470, 75), wModeSelection, COMBOBOX_IPADDR);
int ipi = 0;
while(netManager.local_addr[ipi]) {
myswprintf(dataManager.strBuffer, L"%d.%d.%d.%d", netManager.local_addr[ipi] & 0xff, (netManager.local_addr[ipi] >> 8) & 0xff,
(netManager.local_addr[ipi] >> 16) & 0xff, (netManager.local_addr[ipi] >> 24) & 0xff);
cbIPList->addItem(dataManager.strBuffer);
ipi++;
}
cbIPList->setSelected(0);
btnModeExit = env->addButton(rect<s32>(380, 355, 470, 380), wModeSelection, BUTTON_MODE_EXIT, L"退出");
//img
wCardImg = env->addStaticText(L"", rect<s32>(1, 1, 199, 273), true, false, 0, -1, true);
......
......@@ -223,6 +223,7 @@ public:
irr::gui::IGUIComboBox* cbDeckSel;
irr::gui::IGUIButton* btnDeckEdit;
irr::gui::IGUIStaticText* stModeStatus;
irr::gui::IGUIComboBox* cbIPList;
irr::gui::IGUIButton* btnModeExit;
//message
irr::gui::IGUIWindow* wMessage;
......@@ -348,6 +349,7 @@ extern Game* mainGame;
#define BUTTON_SAVE_LOG 100
#define BUTTON_CLEAR_LOG 101
#define LISTBOX_LOG 102
#define COMBOBOX_IPADDR 109
#define BUTTON_LAN_START_SERVER 110
#define BUTTON_LAN_CANCEL_SERVER 111
#define BUTTON_LAN_CONNECT 112
......
......@@ -3,14 +3,13 @@
namespace ygo {
const unsigned short PROTO_VERSION = 0x1016;
const unsigned short PROTO_VERSION = 0x1017;
bool NetManager::CreateHost() {
bool NetManager::CreateHost(int ipindex) {
wchar_t* pstr;
int wp;
hInfo.identifier = NETWORK_SERVER_ID;
hInfo.version = PROTO_VERSION;
hInfo.address = mainGame->netManager.local_addr;
for(wp = 0, pstr = (wchar_t*)mainGame->ebServerName->getText(); wp < 19 && pstr[wp]; ++wp)
hInfo.name[wp] = pstr[wp];
hInfo.port = serv_port;
......@@ -35,7 +34,10 @@ bool NetManager::CreateHost() {
BOOL opt = TRUE;
setsockopt(sBHost, SOL_SOCKET, SO_BROADCAST, (const char*)&opt, sizeof(BOOL));
SOCKADDR_IN local;
local.sin_addr.s_addr = htonl(INADDR_ANY);
if(ipindex == -1)
local.sin_addr.s_addr = htonl(INADDR_ANY);
else
local.sin_addr.s_addr = local_addr[ipindex];
local.sin_family = AF_INET;
local.sin_port = htons(7913);
if(::bind(sBHost, (sockaddr*)&local, sizeof(sockaddr)) == SOCKET_ERROR) {
......@@ -65,14 +67,17 @@ bool NetManager::CancelHost() {
closesocket(sListen);
is_creating_host = false;
}
bool NetManager::RefreshHost() {
bool NetManager::RefreshHost(int ipindex) {
sBClient = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if(sBClient == INVALID_SOCKET)
return false;
BOOL opt = TRUE;
setsockopt(sBClient, SOL_SOCKET, SO_BROADCAST, (const char*)&opt, sizeof(BOOL));
SOCKADDR_IN local;
local.sin_addr.s_addr = htonl(INADDR_ANY);
if(ipindex == -1)
local.sin_addr.s_addr = htonl(INADDR_ANY);
else
local.sin_addr.s_addr = local_addr[ipindex];
local.sin_family = AF_INET;
local.sin_port = htons(7912);
hReq.identifier = NETWORK_CLIENT_ID;
......@@ -154,18 +159,26 @@ int NetManager::GetLocalAddress() {
hostent* host = gethostbyname(hname);
if(!host)
return 0;
return *(int*)host->h_addr_list[0];
int i = 0;
for(i = 0; i < 8; ++i) {
local_addr[i] = 0;
if(host->h_addr_list[i] == 0)
break;
local_addr[i] = *(unsigned int*)host->h_addr_list[i];
}
return i;
}
int NetManager::BroadcastServer(void* np) {
NetManager* net = (NetManager*)np;
SOCKADDR_IN sockTo;
sockTo.sin_addr.s_addr = htonl(INADDR_BROADCAST);
sockTo.sin_family = AF_INET;
sockTo.sin_port = htons(7912);
int recvLen = recvfrom(net->sBHost, (char*)&net->hReq, sizeof(HostRequest), 0, 0, 0);
while(recvLen != 0 && recvLen != SOCKET_ERROR) {
if(recvLen == sizeof(HostRequest) && net->hReq.identifier == NETWORK_CLIENT_ID)
if(recvLen == sizeof(HostRequest) && net->hReq.identifier == NETWORK_CLIENT_ID) {
sockTo.sin_addr.s_addr = htonl(INADDR_BROADCAST);
sendto(net->sBHost, (const char*)&net->hInfo, sizeof(HostInfo), 0, (sockaddr*)&sockTo, sizeof(sockaddr));
}
recvLen = recvfrom(net->sBHost, (char*)&net->hReq, sizeof(HostRequest), 0, 0, 0);
}
net->is_creating_host = false;
......@@ -191,8 +204,8 @@ int NetManager::BroadcastClient(void* np) {
sockTo.sin_port = htons(7913);
fd_set fds;
timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 500000;
tv.tv_sec = 1;
tv.tv_usec = 0;
FD_ZERO(&fds);
FD_SET(net->sBClient, &fds);
sendto(net->sBClient, (const char*)&net->hReq, sizeof(HostRequest), 0, (sockaddr*)&sockTo, sizeof(sockaddr));
......@@ -201,10 +214,13 @@ int NetManager::BroadcastClient(void* np) {
int result = select(0, &fds, 0, 0, &tv);
std::set<int> addrset;
net->hosts.clear();
SOCKADDR_IN sockFrom;
int sz = sizeof(SOCKADDR_IN);
while(result != 0 && result != SOCKET_ERROR) {
int recvLen = recvfrom(net->sBClient, (char*)&net->hInfo, sizeof(HostInfo), 0, 0, 0);
int recvLen = recvfrom(net->sBClient, (char*)&net->hInfo, sizeof(HostInfo), 0, (sockaddr*)&sockFrom, &sz);
if(recvLen == sizeof(HostInfo) && net->hInfo.identifier == NETWORK_SERVER_ID
&& net->hInfo.version == PROTO_VERSION && addrset.find(net->hInfo.address) == addrset.end()) {
&& net->hInfo.version == PROTO_VERSION && addrset.find(sockFrom.sin_addr.s_addr) == addrset.end()) {
net->hInfo.address = sockFrom.sin_addr.s_addr;
net->hosts.push_back(net->hInfo);
}
result = select(0, &fds, 0, 0, &tv);
......
......@@ -33,7 +33,7 @@ struct HostRequest {
class NetManager {
public:
unsigned int local_addr;
unsigned int local_addr[8];
unsigned short serv_port;
unsigned int remote_addr;
unsigned short remote_port;
......@@ -49,9 +49,9 @@ public:
char send_buf[4096];
char recv_buf[4096];
bool CreateHost();
bool CreateHost(int ipindex);
bool CancelHost();
bool RefreshHost();
bool RefreshHost(int ipindex);
bool JoinHost();
bool SendtoRemote(char* buf, int len);
bool WaitClientResponse();
......@@ -89,7 +89,7 @@ public:
p++;
}
static int GetLocalAddress();
int GetLocalAddress();
static int BroadcastServer(void*);
static int BroadcastClient(void*);
static int ListenThread(void*);
......
......@@ -25,7 +25,7 @@ end
function c16255442.operation(e,tp,eg,ep,ev,re,r,rp)
local sg=Duel.GetFieldGroup(tp,LOCATION_HAND,0,nil)
local sct=sg:GetCount()
Duel.SendtoGrave(sg,REASON_EFFECT)
Duel.SendtoGrave(sg,REASON_EFFECT+REASON_DISCARD)
local tg=Duel.GetMatchingGroup(c16255442.filter,tp,LOCATION_GRAVE,0,nil)
if tg:GetCount()>=sct then
Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_ATOHAND)
......
......@@ -11,7 +11,7 @@ function c9059700.initial_effect(c)
c:RegisterEffect(e1)
end
function c9059700.cfilter(c)
return c:IsFaceup() and c:IsAttack() and c:IsSetCard(0xb)
return c:IsPosition(POS_FACEUP_ATTACK) and c:IsSetCard(0xb)
end
function c9059700.condition(e,tp,eg,ep,ev,re,r,rp)
if ep==tp or not Duel.IsExistingMatchingCard(c9059700.cfilter,tp,LOCATION_MZONE,0,1,nil)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment