Esempio n. 1
0
void APower::Initialize(int32 UID)
{
  if (Cast<AMapState>(GetWorld()->GameState) == NULL && !IsInitialized) { return; }
  if (!Cast<AMapState>(GetWorld()->GameState)->PowersDB->CheckExists(UID)) { return; }
  if (Role < ROLE_Authority) {
    ServerInitialize(UID);
  } else {
    DoInitialize(UID);
  }
}
Esempio n. 2
0
int __cdecl main(int argc, char* argv[]) {
    ::SetDllDirectory("");

#ifndef _WIN64
    HINSTANCE hKernel32 = ::LoadLibrary("Kernel32.dll");

    typedef BOOL (WINAPI * SPDEPP)(DWORD);
    SPDEPP pSPDEPP = (SPDEPP)::GetProcAddress(hKernel32, "SetProcessDEPPolicy");

    if(pSPDEPP != NULL) {
        pSPDEPP(PROCESS_DEP_ENABLE);
    }

    ::FreeLibrary(hKernel32);
#endif

	sTitle = "PtokaX DC Hub " + string(PtokaXVersionString);
#ifdef _DEBUG
	sTitle += " [debug]";
#endif

#ifdef _DEBUG
//    AllocConsole();
//    hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
//    Cout("PtokaX Debug console\n");
#endif
	
	char sBuf[MAX_PATH+1];
	::GetModuleFileName(NULL, sBuf, MAX_PATH);
	char * sPath = strrchr(sBuf, '\\');
	if(sPath != NULL) {
		PATH = string(sBuf, sPath-sBuf);
	} else {
		PATH = sBuf;
	}

	char * sServiceName = NULL;
	
	bool bInstallService = false;
	
	for(int i = 0; i < argc; i++) {
	    if(stricmp(argv[i], "-s") == NULL || stricmp(argv[i], "/service") == NULL) {
	    	if(++i == argc) {
	            AppendLog("Missing service name!");
	            return EXIT_FAILURE;
	    	}
	    	sServiceName = argv[i];
	    	bService = true;
	    } else if(stricmp(argv[i], "-c") == 0) {
	        if(++i == argc) {
	            printf("Missing config directory!");
	            return EXIT_FAILURE;
	        }
	
	        size_t szLen = strlen(argv[i]);
	        if(szLen >= 1 && argv[i][0] != '\\' && argv[i][0] != '/') {
	            if(szLen < 4 || (argv[i][1] != ':' || (argv[i][2] != '\\' && argv[i][2] != '/'))) {
	                printf("Config directory must be absolute path!");
	                return EXIT_FAILURE;
	            }
	    	}
	
	    	if(argv[i][szLen - 1] == '/' || argv[i][szLen - 1] == '\\') {
	            PATH = string(argv[i], szLen - 1);
	    	} else {
	            PATH = string(argv[i], szLen);
	        }
	    
	        if(DirExist(PATH.c_str()) == false) {
	            if(CreateDirectory(PATH.c_str(), NULL) == 0) {
	                printf("Config directory not exist and can't be created!");
	                return EXIT_FAILURE;
	            }
	        }
	    } else if(stricmp(argv[i], "-i") == NULL || stricmp(argv[i], "/install") == NULL) {
	    	if(++i == argc) {
	            printf("Please specify service name!");
	    		return EXIT_FAILURE;
	    	}
	    	sServiceName = argv[i];
	    	bInstallService = true;
	    } else if(stricmp(argv[i], "-u") == NULL || stricmp(argv[i], "/uninstall") == NULL) {
	    	if(++i == argc) {
	            printf("Please specify service name!");
	    		return EXIT_FAILURE;
	    	}
	    	sServiceName = argv[i];
	    	return UninstallService(sServiceName);
	    } else if(stricmp(argv[i], "-v") == NULL || stricmp(argv[i], "/version") == NULL) {
	    	printf((sTitle+" built on "+__DATE__+" "+__TIME__).c_str());
	    	return EXIT_SUCCESS;
	    } else if(stricmp(argv[i], "-h") == NULL || stricmp(argv[i], "/help") == NULL) {
	    	printf("PtokaX [-c <configdir>] [-i <servicename>] [-u <servicename>] [-v]");
	    	return EXIT_SUCCESS;
	    } else if(stricmp(argv[i], "/nokeycheck") == NULL) {
	        bCmdNoKeyCheck = true;
	    } else if(stricmp(argv[i], "/generatexmllanguage") == NULL) {
	        LangMan::GenerateXmlExample();
	        return EXIT_SUCCESS;
	    }
	}

	if(bInstallService == true) {
	    if(sPath == NULL && strcmp(PATH.c_str(), sBuf) == 0) {
	        return InstallService(sServiceName, NULL);
		} else {
			return InstallService(sServiceName, PATH.c_str());
		}
	}

    ExceptionHandlingInitialize(PATH, sBuf);

	if(bService == false) {
	    ServerInitialize();
	
	    if(ServerStart() == false) {
	        printf("Server start failed!");

            ExceptionHandlingUnitialize();

	        return EXIT_FAILURE;
	    } else {
	        printf((sTitle+" running...\n").c_str());
	    }

	    MSG msg;
	    BOOL bRet;

	    while((bRet = ::GetMessage(&msg, NULL, 0, 0)) != 0) {
	        if(bRet == -1) {
	            // handle the error and possibly exit
	        } else {
	            if(msg.message == WM_USER+1) {
	                break;
	            } else if(msg.message == WM_TIMER) {
                    if(msg.wParam == srvLoopTimer) {
                        srvLoop->Looper();
                    } else if(msg.wParam == regtimer) {
                        ServerOnRegTimer();
                    } else {
                        //Must be script timer
                        ScriptOnTimer(msg.wParam);
                    }
                }
	
	    		::TranslateMessage(&msg);
	            ::DispatchMessage(&msg);
	        }
	    }

        ExceptionHandlingUnitialize();
	} else {
	    SERVICE_TABLE_ENTRY DispatchTable[] = {
	        { sServiceName, StartService },
	        { NULL, NULL }
	    };
	       
	    if(StartServiceCtrlDispatcher(DispatchTable) == false) {
			AppendLog("StartServiceCtrlDispatcher failed ("+string((uint32_t)GetLastError())+")!");

            ExceptionHandlingUnitialize();

	        return EXIT_FAILURE;
	    }
	}

    return EXIT_SUCCESS;
}
Esempio n. 3
0
static void WINAPI StartService(DWORD /*argc*/, char* argv[]) {
	ssh = RegisterServiceCtrlHandler(argv[0], CtrlHandler);
	
	if(ssh == NULL) {
		AppendLog("RegisterServiceCtrlHandler failed ("+string((uint32_t)GetLastError())+")!");
	    return;
	}
	
	ss.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
	ss.dwCurrentState = SERVICE_START_PENDING;
	ss.dwControlsAccepted = SERVICE_ACCEPT_SHUTDOWN | SERVICE_ACCEPT_STOP;
	ss.dwWin32ExitCode = NO_ERROR;
	ss.dwCheckPoint = 0;
	ss.dwWaitHint = 10 * 1000;
	
	if(SetServiceStatus(ssh, &ss) == false) {
		AppendLog("StartService::SetServiceStatus failed ("+string((uint32_t)GetLastError())+")!");
		return;
	}
	
	ServerInitialize();
	
	if(ServerStart() == false) {
	    AppendLog("Server start failed!");
		ss.dwCurrentState = SERVICE_STOPPED;
		SetServiceStatus(ssh, &ss);
		return;
	}
	
	ss.dwCurrentState = SERVICE_RUNNING;
	
	if(SetServiceStatus(ssh, &ss) == false) {
		AppendLog("StartService::SetServiceStatus1 failed ("+string((uint32_t)GetLastError())+")!");
		return;
	}

	MSG msg;
	BOOL bRet;
	        
	while((bRet = GetMessage(&msg, NULL, 0, 0)) != 0) {
	    if(bRet == -1) {
	        // handle the error and possibly exit
	    } else {
	        if(msg.message == WM_USER+1) {
	            break;
	        } else if(msg.message == WM_TIMER) {
                if(msg.wParam == sectimer) {
                    ServerOnSecTimer();
                } else if(msg.wParam == srvLoopTimer) {
                    srvLoop->Looper();
                } else if(msg.wParam == regtimer) {
                    ServerOnRegTimer();
                } else {
                    //Must be script timer
                    ScriptOnTimer(msg.wParam);
                }
            }

	    	TranslateMessage(&msg);
	        DispatchMessage(&msg);
	    }
	}

    ExceptionHandlingUnitialize();

	ss.dwCurrentState = SERVICE_STOPPED;
	SetServiceStatus(ssh, &ss);
}
Esempio n. 4
0
int main(int argc, char* argv[]) {
	sTitle = "PtokaX DC Hub " + string(PtokaXVersionString);
	
#ifdef _DEBUG
	sTitle += " [debug]";
#endif
	
	for(int i = 0; i < argc; i++) {
	    if(strcasecmp(argv[i], "-d") == 0) {
	    	bDaemon = true;
	    } else if(strcasecmp(argv[i], "-c") == 0) {
	    	if(++i == argc) {
	            printf("Missing config directory!\n");
	            return EXIT_FAILURE;
	    	}
	
			if(argv[i][0] != '/') {
	            printf("Config directory must be absolute path!\n");
	            return EXIT_FAILURE;
			}
	
	        size_t szLen = strlen(argv[i]);
			if(argv[i][szLen - 1] == '/') {
	            PATH = string(argv[i], szLen - 1);
			} else {
	            PATH = string(argv[i], szLen);
	        }
	
	        if(DirExist(PATH.c_str()) == false) {
	        	if(mkdir(PATH.c_str(), S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP) == -1) {
	                if(bDaemon == true) {
	                    syslog(LOG_USER | LOG_ERR, "Config directory not exist and can't be created!\n");
	                } else {
	                    printf("Config directory not exist and can't be created!");
	                }
	            }
            }
	    } else if(strcasecmp(argv[i], "-v") == 0) {
	        printf("%s built on %s %s\n", sTitle.c_str(), __DATE__, __TIME__);
	        return EXIT_SUCCESS;
	    } else if(strcasecmp(argv[i], "-h") == 0) {
	        printf("PtokaX [-d] [-c <configdir>] [-v]\n");
	        return EXIT_SUCCESS;
	    } else if(strcasecmp(argv[i], "/generatexmllanguage") == 0) {
	        LangMan::GenerateXmlExample();
	        return EXIT_SUCCESS;
	    }
	}
	
	if(PATH.size() == 0) {
	    char* home;
	    char curdir[PATH_MAX];
	    if(bDaemon == true && (home = getenv("HOME")) != NULL) {
	        PATH = string(home) + "/.PtokaX";
	            
	        if(DirExist(PATH.c_str()) == false) {
	            if(mkdir(PATH.c_str(), S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP) == -1) {
	                syslog(LOG_USER | LOG_ERR, "Config directory not exist and can't be created!\n");
	            }
	        }
	    } else if(getcwd(curdir, PATH_MAX) != NULL) {
	        PATH = curdir;
	    } else {
	        PATH = ".";
	    }
	}
	
	if(bDaemon == true) {
	    printf("Starting %s as daemon using %s as config directory.\n", sTitle.c_str(), PATH.c_str());
	
	    pid_t pid1 = fork();
	    if(pid1 == -1) {
	        syslog(LOG_USER | LOG_ERR, "First fork failed!\n");
	        return EXIT_FAILURE;
	    } else if(pid1 > 0) {
	        return EXIT_SUCCESS;
	    }
	
	    if(setsid() == -1) {
	        syslog(LOG_USER | LOG_ERR, "Setsid failed!\n");
	        return EXIT_FAILURE;
	    }
	
	    pid_t pid2 = fork();
	    if(pid2 == -1) {
	        syslog(LOG_USER | LOG_ERR, "Second fork failed!\n");
	        return EXIT_FAILURE;
	    } else if(pid2 > 0) {
            return EXIT_SUCCESS;
	    }
	
	    chdir("/");
	
	    close(STDIN_FILENO);
	    close(STDOUT_FILENO);
	    close(STDERR_FILENO);
	
	    umask(117);
	
	    if(open("/dev/null", O_RDWR) == -1) {
	        syslog(LOG_USER | LOG_ERR, "Failed to open /dev/null!\n");
	        return EXIT_FAILURE;
	    }
	
	    dup(0);
	    dup(0);
	}
	
	sigset_t sst;
	sigemptyset(&sst);
	sigaddset(&sst, SIGPIPE);
	sigaddset(&sst, SIGURG);
	sigaddset(&sst, SIGALRM);
	sigaddset(&sst, SIGSCRTMR);
	sigaddset(&sst, SIGREGTMR);
	
	if(bDaemon == true) {
	    sigaddset(&sst, SIGHUP);
	}
	
	pthread_sigmask(SIG_BLOCK, &sst, NULL);
	
	struct sigaction sigact;
	sigact.sa_handler = SigHandler;
	sigemptyset(&sigact.sa_mask);
	sigact.sa_flags = 0;
	
	if(sigaction(SIGINT, &sigact, NULL) == -1) {
	    AppendDebugLog("%s - [ERR] Cannot create sigaction SIGINT in main\n", 0);
	    exit(EXIT_FAILURE);
	}
	
	if(sigaction(SIGTERM, &sigact, NULL) == -1) {
	    AppendDebugLog("%s - [ERR] Cannot create sigaction SIGTERM in main\n", 0);
	    exit(EXIT_FAILURE);
	}
	
	if(sigaction(SIGQUIT, &sigact, NULL) == -1) {
	    AppendDebugLog("%s - [ERR] Cannot create sigaction SIGQUIT in main\n", 0);
	    exit(EXIT_FAILURE);
	}
	
	if(bDaemon == false && sigaction(SIGHUP, &sigact, NULL) == -1) {
	    AppendDebugLog("%s - [ERR] Cannot create sigaction SIGHUP in main\n", 0);
	    exit(EXIT_FAILURE);
	}

	ServerInitialize();

	if(ServerStart() == false) {
	    if(bDaemon == false) {
	        printf("Server start failed!\n");
	    } else {
	        syslog(LOG_USER | LOG_ERR, "Server start failed!\n");
	    }
	    return EXIT_FAILURE;
	} else if(bDaemon == false) {
	    printf("%s running...\n", sTitle.c_str());
	}

    struct timespec sleeptime;
    sleeptime.tv_sec = 0;
    sleeptime.tv_nsec = 100000000;

	while(true) {
	    srvLoop->Looper();
	
	    if(bServerTerminated == true) {
	        break;
	    }
	
        nanosleep(&sleeptime, NULL);
	}

	if(bDaemon == false) {
	    printf("%s ending...\n", sTitle.c_str());
	}

    return EXIT_SUCCESS;
}
Esempio n. 5
0
EC_WebView::EC_WebView(IModule *module) :
    IComponent(module->GetFramework()),
    webview_(0),
    renderTimer_(0),
    webviewLoading_(false),
    webviewHasContent_(false),
    componentPrepared_(false),
    myControllerId_(0),
    currentControllerName_(""),
    webviewUrl(this, "View URL", QString()),
    webviewSize(this, "View Size", QSize(800,600)),
    renderSubmeshIndex(this, "Render Submesh", 0),
    renderRefreshRate(this, "Render FPS", 0),
    interactive(this, "Interactive", false),
    controllerId(this, "ControllerId", NoneControlID),
    illuminating(this, "Illuminating", true)
{
    interactionMetaData_ = new AttributeMetadata();

    static AttributeMetadata submeshMetaData;
    static AttributeMetadata refreshRateMetadata;
    static AttributeMetadata nonDesignableMetadata;
    static bool metadataInitialized = false;
    if (!metadataInitialized)
    {
        submeshMetaData.minimum = "0";
        submeshMetaData.step = "1";
        refreshRateMetadata.minimum = "0";
        refreshRateMetadata.maximum = "25";
        refreshRateMetadata.step = "1";
        nonDesignableMetadata.designable = false;
        metadataInitialized = true;
    }
    renderSubmeshIndex.SetMetadata(&submeshMetaData);
    renderRefreshRate.SetMetadata(&refreshRateMetadata);
    controllerId.SetMetadata(&nonDesignableMetadata);

    // Initializations depending if we are on the server or client
    TundraLogic::TundraLogicModule *tundraLogic = GetFramework()->GetModule<TundraLogic::TundraLogicModule>();
    if (tundraLogic)
    {
        if (tundraLogic->IsServer())
            ServerInitialize(tundraLogic->GetServer().get());
        else
            myControllerId_ = tundraLogic->GetClient()->GetConnectionID();
    }

    // Don't do anything beyond if rendering is not enabled
    // aka headless server. UI enabled server may continue, but they are not going
    // to have perfect browsing sync as the entity actions are sent to "peers" as in other clients.
    if (!ViewEnabled() || GetFramework()->IsHeadless())
        return;

    // Connect window size changes to update rendering as the ogre textures go black.
    if (GetFramework()->Ui()->MainWindow())
        connect(GetFramework()->Ui()->MainWindow(), SIGNAL(WindowResizeEvent(int,int)), SLOT(RenderDelayed()), Qt::UniqueConnection);

    // Connect signals from IComponent
    connect(this, SIGNAL(ParentEntitySet()), SLOT(PrepareComponent()), Qt::UniqueConnection);
    connect(this, SIGNAL(AttributeChanged(IAttribute*, AttributeChange::Type)), SLOT(AttributeChanged(IAttribute*, AttributeChange::Type)), Qt::UniqueConnection);
    
    // Prepare render timer
    renderTimer_ = new QTimer(this);
    connect(renderTimer_, SIGNAL(timeout()), SLOT(Render()), Qt::UniqueConnection);

    // Prepare scene interactions
    SceneInteractWeakPtr sceneInteract = GetFramework()->Scene()->GetSceneIteract();
    if (!sceneInteract.isNull())
    {
        connect(sceneInteract.data(), SIGNAL(EntityMousePressed(Scene::Entity*, Qt::MouseButton, RaycastResult*)), 
                SLOT(EntityClicked(Scene::Entity*, Qt::MouseButton, RaycastResult*)));
    }