Esempio n. 1
0
bool Socket::HandleVerpassInput()
{
    Player* mob = GetPlayer();
    std::string input = PopCommand();

    if (!IsValidPassword(input))
        {
            Write("That password isn't valid, please try again.\n");
            return true;
        }

    mob->SetTempPassword(input);
//passwords  did not match, transfer control back to new password.
    if (!mob->ComparePassword())
        {
            Write("That password isn't valid, please try again.\n");
            SetConnectionType(ConnectionType::Newpass);
            return true;
        }

    Write(TELNET_ECHO_OFF);
    Write("What is your gender? Please enter male or female.\n");
    SetConnectionType(ConnectionType::Gender);

    return true;
}
Esempio n. 2
0
bool Socket::HandleGenderInput()
{
    bool gf = false;
    Player* mob = GetPlayer();
    std::string input = PopCommand();
    Lower(input);

    if (input.length() >= 1)
        {
            if (input[0] == 'm')
                {
                    mob->SetGender(Gender::Male);
                    gf = true;
                }
            if (input[0] == 'f')
                {
                    mob->SetGender(Gender::Female);
                    gf = true;
                }
        }

    if (gf)
        {
            InitializeNewPlayer();
        }

    return true;
}
Esempio n. 3
0
    void ArAIProperty::Update(float dt)
    {
        ArProperty::Update(dt);

        // update the behavior tree
        mAIRoot->execute((void*) this);

        auto gameEntity = GetEntity<ArGameEntity>();
        if (gameEntity->IsDead())
        {
            ClearAIList();
        }

        if (mAIList.empty())
        {
            UpdateDummyAI(dt);
            return;
        }

        auto pAI = mAIList.front();
        while (pAI->IsEnd())
        {
            PopCommand();
            if (mAIList.empty())
            {
                return;
            }
            pAI = mAIList.front();
        }
        pAI->Update(dt);
    }
Esempio n. 4
0
bool Socket::HandleGameInput()
{
    World* world = World::GetPtr();
    Player* mob = GetPlayer();
    std::string input;

//check to see if an input handler was associated with the socket before we pass to command parsing
    if (HasHandle())
        {
            HandleInput();
            return true;
        }

//No handle was found, pass on to command parsing
    input=PopCommand();
    if (!input.length())
        {
            return true;
        }
    if (!world->DoCommand(mob, input))
        {
            mob->Message(MSG_ERROR, "I did not understand that.");
            return false;
        }

    return true;
}
Esempio n. 5
0
bool Socket::HandlePasswordInput()
{
    World* world = World::GetPtr();
    Server* server = world->GetServer();
    Player* mobile = GetPlayer();
    std::string input;

    input = PopCommand();
    mobile->SetTempPassword(input);

    if (!mobile->ComparePassword())
        {
            Write("That password isn't valid!\n");
            mobile->IncInvalidPassword();
            return false;
        }

    Write(TELNET_ECHO_ON);
    SetConnectionType(CON_Game);
    mobile->SetSocket(this);
    if (server->GetLinkdeadUser(mobile->GetName()))
        {
            server->RemoveLinkdeadUser(mobile->GetName());
            Write("Reconnected.\n");
            return true;
        }

    mobile->SetLastLogin((UINT)time(NULL));
    mobile->EnterGame(false);
    return true;
}
int DeviceManagerThread::Run()
{
    ThreadCommand::PopBuffer command;

    SetThreadName("OVR::DeviceManagerThread");
    LogText("OVR::DeviceManagerThread - running (ThreadId=%p).\n", GetThreadId());
    

    while(!IsExiting())
    {
        // PopCommand will reset event on empty queue.
        if (PopCommand(&command))
        {
            command.Execute();
        }
        else
        {
            bool commands = 0;
            do
            {
                int n = poll(&PollFds[0], PollFds.GetSize(), -1);

                for (int i = 0; i < PollFds.GetSize(); i++)
                {
                    if (PollFds[i].revents & POLLERR)
                    {
                        OVR_DEBUG_LOG(("poll: error on [%d]: %d", i, PollFds[i].fd));
                    }
                    else if (PollFds[i].revents & POLLIN)
                    {
                        if (FdNotifiers[i])
                            FdNotifiers[i]->OnEvent(i, PollFds[i].fd);
                        else if (i == 0) // command
                        {
                            char dummy[128];                            
                            read(PollFds[i].fd, dummy, 128);
                            commands = 1;
                        }
                    }

                    if (PollFds[i].revents & POLLHUP)
                        PollFds[i].events = 0;

                    if (PollFds[i].revents != 0)
                    {
                        n--;
                        if (n == 0)
                            break;
                    }
                }                    
            } while (PollFds.GetSize() > 0 && !commands);
        }
    }

    LogText("OVR::DeviceManagerThread - exiting (ThreadId=%p).\n", GetThreadId());
    return 0;
}
Esempio n. 7
0
bool Socket::HandleNameInput()
{
    Player* mob = nullptr;
    std::string input;
    World* world = World::GetPtr();
    Server* server = world->GetServer();
    input = PopCommand();

//new player:
    if (input=="new")
        {
            Write("Welcome, what name would you like?\n");
            AllocatePlayer();
            mob = GetPlayer();
            SetConnectionType(CON_Newname);
            return true;
        }

//checks to see if the username is valid
    if (!IsValidUserName(input))
        {
            Write("Invalid name, try again.\n");
            return true;
        }

//check to see if the player exists
    if (!PlayerExists(input))
        {
            Write("That player doesn't exist.\nWhat is your name? Type new for a new character.\n");
            return true;
        }

    mob = server->GetLinkdeadUser(input);
    if (mob)
        {
            _mobile = mob;
            Write(TELNET_ECHO_OFF);
            Write("\n");
            Write("Password?\n");
            SetConnectionType(CON_Password);
            return true;
        }

    AllocatePlayer();
    mob = GetPlayer();
//set the players name to the one specified and try to load the file.
    mob->SetName(input);
    mob->Load();

    Write(TELNET_ECHO_OFF);
    Write("\n");
    Write("Password?\n");
    SetConnectionType(CON_Password);
    return true;
}
Esempio n. 8
0
BOOL Socket::HandleInput()
{
    if (HasHandle())
        {
            in_data* data = _input->top();
            data->handle->Input(_input->top()->args, PopCommand());
            ClrInBuffer();
            return true;
        }

    return false;
}
Esempio n. 9
0
    void Controller::HandleCommand() {
        if (!HasCommands())
            return;

        while (HasCommands()) {
            Command cmd = PopCommand();

            switch (cmd.what) {
                case Cmd::kResume:
                    mTimer->Resume();
                    mStatus = State::kRunning;
                    break;
                case Cmd::kPause:
                    if (mStatus == State::kRunning) {
                        mTimer->Pause();
                        std::unique_lock<std::mutex> locker(mConditionMutex);
                        mStatus = State::kPaused;
                        while (mStatus == State::kPaused) {
                            mCondition.wait(locker);
                        }
                    }
                    break;
                case Cmd::kSeek:
                    if (mStatus == State::kRunning) {
                        time_t timepoint = 0;
                        *reinterpret_cast<int*>(&timepoint) = cmd.arg1;
                        *(reinterpret_cast<int*>(&timepoint) + 1) = cmd.arg2;
                        mManager->SeekTo(timepoint);
                    }
                    break;
                case Cmd::kResize:
                    mDisplayer->Resize(cmd.arg1, cmd.arg2);
                    mManager->GetConfig()->MeasureFlag++;
                    break;
                case Cmd::kReLayout:
                    mManager->ReLayout();
                    break;
                case Cmd::kStop:
                    mStatus = State::kStopped;
                    break;
            }
        }
    }
Esempio n. 10
0
bool Socket::HandleNewpassInput()
{
    std::string input;
    Player* mob = GetPlayer();

    input=PopCommand();
    if (!IsValidPassword(input))
        {
            Write("That password isn't valid, please try again.\n");
            return true;
        }

//transfer control to password verification
    Write("Please re-enter your password for varification.\n");
    mob->SetPassword(input);
    SetConnectionType(ConnectionType::Verpass);

    return true;
}
Esempio n. 11
0
bool Socket::HandleNameInput()
{
    Player* mob = nullptr;
    std::string input;

//we associate a player with the socket object so we can store data and later load.
    AllocatePlayer();
    mob = GetPlayer();
    input = PopCommand();

//new player:
    if (input=="new")
        {
            Write("Welcome, what name would you like?\n");
            SetConnectionType(ConnectionType::Newname);
            return true;
        }

//checks to see if the username is valid
    if (!IsValidUserName(input))
        {
            Write("Invalid name, try again.\n");
            return true;
        }

//check to see if the player exists
    if (!PlayerExists(input))
        {
            Write("That player doesn't exist.\nWhat is your name? Type new for a new character.\n");
            return true;
        }

//set the players name to the one specified and try to load the file.
    mob->SetName(input);
    mob->Load();

    Write(TELNET_ECHO_OFF);
    Write("\n");
    Write("Password?\n");
    SetConnectionType(ConnectionType::Password);
    return true;
}
Esempio n. 12
0
bool Socket::HandlePasswordInput()
{
    Player* mobile = GetPlayer();
    std::string input;

    input = PopCommand();
    mobile->SetTempPassword(input);

    if (!mobile->ComparePassword())
        {
            Write("That password isn't valid!\n");
            mobile->IncInvalidPassword();
            return false;
        }

    Write(TELNET_ECHO_ON);
    SetConnectionType(ConnectionType::Game);
    mobile->SetSocket(this);
    mobile->SetLastLogin((UINT)time(NULL));
    mobile->EnterGame(false);

    return true;
}
Esempio n. 13
0
bool Socket::HandleNewnameInput()
{
    std::string input;
    Player* mobile = GetPlayer();
    input = PopCommand();

    if (!IsValidUserName(input))
        {
            Write("That is not a valid username. Usernames must contain 4-12 characters.\nWhat name would you like?\n");
            return true;
        }
    if (PlayerExists(input))
        {
            Write("That player already exists, please try again.\nWhat name would you like?\n");
            return true;
        }

    Write("Please choose a password. Please make your password between 5 and 20 characters long.\nStrong passwords contain both lower and uppercase letters, numbers, letters and a dash ('-').\nEnter your new password?\n");
    Write(TELNET_ECHO_OFF);
//name was valid, set it in the player class.
    mobile->SetName(input);
    SetConnectionType(ConnectionType::Newpass);
    return true;
}
Esempio n. 14
0
int DeviceManagerThread::Run()
{
    ThreadCommand::PopBuffer command;

    SetThreadName("OVR::DeviceManagerThread");
    LogText("OVR::DeviceManagerThread - running (ThreadId=%p).\n", GetThreadId());
    
    // Signal to the parent thread that initialization has finished.
    StartupEvent.SetEvent();

    while(!IsExiting())
    {
        // PopCommand will reset event on empty queue.
        if (PopCommand(&command))
        {
            command.Execute();
        }
        else
        {
            bool commands = 0;
            do
            {
                int waitMs = -1;

                // If devices have time-dependent logic registered, get the longest wait
                // allowed based on current ticks.
                if (!TicksNotifiers.IsEmpty())
                {
                    UInt64 ticksMks = Timer::GetTicks();
                    int  waitAllowed;

                    for (UPInt j = 0; j < TicksNotifiers.GetSize(); j++)
                    {
                        waitAllowed = (int)(TicksNotifiers[j]->OnTicks(ticksMks) / Timer::MksPerMs);
                        if (waitAllowed < waitMs)
                            waitMs = waitAllowed;
                    }
                }

                // wait until there is data available on one of the devices or the timeout expires
                int n = poll(&PollFds[0], PollFds.GetSize(), waitMs);

                if (n > 0)
                {
                    // Iterate backwards through the list so the ordering will not be
                    // affected if the called object gets removed during the callback
                    // Also, the HID data streams are located toward the back of the list
                    // and servicing them first will allow a disconnect to be handled
                    // and cleaned directly at the device first instead of the general HID monitor
                    for (int i=PollFds.GetSize()-1; i>=0; i--)
                    {
                        if (PollFds[i].revents & POLLERR)
                        {
                            OVR_DEBUG_LOG(("poll: error on [%d]: %d", i, PollFds[i].fd));
                        }
                        else if (PollFds[i].revents & POLLIN)
                        {
                            if (FdNotifiers[i])
                                FdNotifiers[i]->OnEvent(i, PollFds[i].fd);
                            else if (i == 0) // command
                            {
                                char dummy[128];
                                read(PollFds[i].fd, dummy, 128);
                                commands = 1;
                            }
                        }

                        if (PollFds[i].revents & POLLHUP)
                            PollFds[i].events = 0;

                        if (PollFds[i].revents != 0)
                        {
                            n--;
                            if (n == 0)
                                break;
                        }
                    }
                }
            } while (PollFds.GetSize() > 0 && !commands);
        }
    }

    LogText("OVR::DeviceManagerThread - exiting (ThreadId=%p).\n", GetThreadId());
    return 0;
}
Esempio n. 15
0
int DeviceManagerThread::Run()
{

    SetThreadName("OVR::DeviceManagerThread");
    LogText("OVR::DeviceManagerThread - running (ThreadId=0x%p).\n", GetThreadId());

    // Store out the run loop ref.
    RunLoop = CFRunLoopGetCurrent();

    // Create a 'source' to enable us to signal the run loop to process the command queue.
    CFRunLoopSourceContext sourceContext;
    memset(&sourceContext, 0, sizeof(sourceContext));
    sourceContext.version = 0;
    sourceContext.info = this;
    sourceContext.perform = &staticCommandQueueSourceCallback;

    CommandQueueSource = CFRunLoopSourceCreate(kCFAllocatorDefault, 0 , &sourceContext);

    CFRunLoopAddSource(RunLoop, CommandQueueSource, kCFRunLoopDefaultMode);


    // Signal to the parent thread that initialization has finished.
    StartupEvent.SetEvent();


    ThreadCommand::PopBuffer command;
   
    while(!IsExiting())
    {
        // PopCommand will reset event on empty queue.
        if (PopCommand(&command))
        {
            command.Execute();
        }
        else
        {
            SInt32 exitReason = 0;
            do {

                UInt32 waitMs = INT_MAX;

                // If devices have time-dependent logic registered, get the longest wait
                // allowed based on current ticks.
                if (!TicksNotifiers.IsEmpty())
                {
                    UInt64 ticksMks = Timer::GetTicks();
                    UInt32  waitAllowed;

                    for (UPInt j = 0; j < TicksNotifiers.GetSize(); j++)
                    {
                        waitAllowed = (UInt32)(TicksNotifiers[j]->OnTicks(ticksMks) / Timer::MksPerMs);
                        if (waitAllowed < waitMs)
                            waitMs = waitAllowed;
                    }
                }
                
                // Enter blocking run loop. We may continue until we timeout in which
                // case it's time to service the ticks. Or if commands arrive in the command
                // queue then the source callback will call 'CFRunLoopStop' causing this
                // to return.
                CFTimeInterval blockInterval = 0.001 * (double) waitMs;
                exitReason = CFRunLoopRunInMode(kCFRunLoopDefaultMode, blockInterval, false);

                if (exitReason == kCFRunLoopRunFinished)
                {
                    // Maybe this will occur during shutdown?
                    break;
                }
                else if (exitReason == kCFRunLoopRunStopped )
                {
                    // Commands need processing or we're being shutdown.
                    break;
                }
                else if (exitReason == kCFRunLoopRunTimedOut)
                {
                    // Timed out so that we can service our ticks callbacks.
                    continue;
                }
                else if (exitReason == kCFRunLoopRunHandledSource)
                {
                    // Should never occur since the last param when we call
                    // 'CFRunLoopRunInMode' is false.
                    OVR_ASSERT(false);
                    break;
                }
                else
                {
                    OVR_ASSERT_LOG(false, ("CFRunLoopRunInMode returned unexpected code"));
                    break;
                }
            }
            while(true);                    
        }
    }

                                   
    CFRunLoopRemoveSource(RunLoop, CommandQueueSource, kCFRunLoopDefaultMode);
    CFRelease(CommandQueueSource);
    
    LogText("OVR::DeviceManagerThread - exiting (ThreadId=0x%p).\n", GetThreadId());

    return 0;
}