Shadowrun: Awakened 29 September 2011 - Build 871
Classes | Functions | Variables
SraClientConnection.cpp File Reference
#include "stdio.h"
#include "stdlib.h"
#include <vector>
#include "Connectivity.h"
#include "LoginPacket.h"
#include "LoginReplyPacket.h"
#include "GetClientCharactersPacket.h"
#include "ConnectToServerPacket.h"
#include "GetServerListPacket.h"
#include "ReplyPacket.h"
#include "CreateCharacterPacket.h"
#include "JoinChannelPacket.h"
#include "LeaveChannelPacket.h"
#include "ChatMessage.h"
#include "SendMessageToChannelPacket.h"
#include "Utils.h"
Include dependency graph for SraClientConnection.cpp:

Go to the source code of this file.

Classes

struct  DEBUGServerReplyMessage
struct  FString
struct  ServerReplyMessages

Functions

 __declspec (dllexport) bool SraConnectToServer(const wchar_t *serverAddress)
const wchar_t *pw if (!m_rServerInterface)

Variables

static RakNet::RakPeerInterfacem_rChatServerInterface
static RakNet::RakPeerInterfacem_rServerInterface
static int myCharID = -1
static int myPID = -1
packet opCode = SraNetwork::ID_LOGIN_REQ
LoginPacket packet
packet password = RakString(convertString(pw).c_str())
static RakNet::PublicKey publicKey
uint32_t sentData
RakNet::BitStream stream
return true
packet username = RakString(convertString(user).c_str())

Function Documentation

__declspec ( dllexport  ) const

Connects to a Sra world server.

Reconnects to a world server after the zone has changed, i.e. the DLL has been unloaded.

Close the world server connection and shut down RakNet interface.

Login client with given credentials. TODO:

  • Use secure sockets !!

Requests the current zone for the active player. This method will return an ip adress and a port, e.g. '127.0.0.1:13001'.

Attention: Because the socket message is much faster than spawning a zone, the zone may not be ready when this method receives the address. So if the client can't connect just try again a few secs later.

Definition at line 86 of file SraClientConnection.cpp.

References SraNetwork::CLIENT_SERVER_PORT, RakNet::RakPeerInterface::Connect(), RakNet::CONNECTION_ATTEMPT_STARTED, RakNet::RakPeerInterface::GetInstance(), m_rServerInterface, RakNet::RakPeerInterface::NumberOfConnections(), publicKey, SraNetwork::SERVER_CLIENT_PORT, RakNet::RakPeerInterface::Startup(), and SraNetwork::WORLD_SERVER_ADDR.

    {
        printf("Start connecting\n");
        //Load public key:
    /*  char public_key[cat::EasyHandshake::PUBLIC_KEY_BYTES];
        FILE* fp;
        fopen_s(&fp, "sra_public.key","r");
        if (!fp) 
        {
            printf("Public key not found!\n");
            return false;
        }
        fread(public_key, sizeof(public_key), 1, fp);
        fclose(fp);
        publicKey.publicKey = public_key;
        publicKey.publicKeyMode = RakNet::PKM_USE_KNOWN_PUBLIC_KEY;
*/
        //Do not connect when the interface is already connected
        if (m_rServerInterface && m_rServerInterface->NumberOfConnections() > 0) 
        {
            printf("Already connected!\n");
            return true;
        }
        //Start connecting
        m_rServerInterface = RakNet::RakPeerInterface::GetInstance();
        RakNet::SocketDescriptor serverSocket(SraNetwork::CLIENT_SERVER_PORT, 0);
        m_rServerInterface->Startup(1, &serverSocket, 1);
        //Convert wchar_t* -> char*
        char *saddr = new char[wcslen(serverAddress)+1];
        size_t res=0;
        wcstombs_s( &res, saddr, strlen(saddr), (const wchar_t*)serverAddress, strlen(saddr));
        //wcstombs(saddr, serverAddress, wcslen(serverAddress));

        printf("Connecting to world server @ %s\n", saddr);
        RakNet::ConnectionAttemptResult result = 
            m_rServerInterface->Connect(SraNetwork::WORLD_SERVER_ADDR, SraNetwork::SERVER_CLIENT_PORT, 0, 0, &publicKey);

        // Only check if the connection attempt was succesfull, everything else will be handled by poll()
        if (result != RakNet::ConnectionAttemptResult::CONNECTION_ATTEMPT_STARTED)
        {
            return false;
        }
        return true;
    }
const wchar_t* pw if ( m_rServerInterface)

Variable Documentation

RakNet chat server interface.

Definition at line 74 of file SraClientConnection.cpp.

RakNet server interface.

Definition at line 70 of file SraClientConnection.cpp.

Referenced by __declspec(), and SraNetwork::ChatServer::ServerConnectionThread().

int myCharID = -1 [static]

Player character id, this is only valid after selecting a character.

Definition at line 79 of file SraClientConnection.cpp.

int myPID = -1 [static]

Player id for this client, only valid after a call to SraLogin.

Definition at line 77 of file SraClientConnection.cpp.

packet opCode = SraNetwork::ID_LOGIN_REQ

Definition at line 231 of file SraClientConnection.cpp.

Referenced by SraNetwork::MessagePump::Run().

packet password = RakString(convertString(pw).c_str())

Definition at line 233 of file SraClientConnection.cpp.

Public key.

Definition at line 81 of file SraClientConnection.cpp.

Referenced by __declspec().

packet Serialize & stream
return true

Definition at line 243 of file SraClientConnection.cpp.

packet username = RakString(convertString(user).c_str())

Definition at line 232 of file SraClientConnection.cpp.


Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net