* Added a Login GUI. Not beautiful, but at least it works.
** Login GUI only appears when GUI is activated in conf and either Password or Accountname are not set ** Don't resize the Login Window ** Community Website button doesn't work yet, but Quit does * Added a dynamic framerate limiter, though i think it's overkill. See comments in PseuGUI.cpp * Changed std::cout to logdebug in the Image and MeshLoaders
This commit is contained in:
parent
5f3751fe13
commit
8453f04d66
@ -1,5 +1,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "common.h"
|
||||||
#include "irrlicht/irrlicht.h"
|
#include "irrlicht/irrlicht.h"
|
||||||
#include "SImage.h"
|
#include "SImage.h"
|
||||||
#include "CImageLoaderBLP.h"
|
#include "CImageLoaderBLP.h"
|
||||||
@ -19,7 +20,7 @@ namespace video
|
|||||||
//! based on the file extension (e.g. ".tga")
|
//! based on the file extension (e.g. ".tga")
|
||||||
bool CImageLoaderBLP::isALoadableFileExtension(const c8* fileName) const
|
bool CImageLoaderBLP::isALoadableFileExtension(const c8* fileName) const
|
||||||
{
|
{
|
||||||
// std::cout << "Checking for file extension\n";
|
// Checking for file extension
|
||||||
return strstr(fileName, ".blp")!=0;
|
return strstr(fileName, ".blp")!=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,29 +28,29 @@ bool CImageLoaderBLP::isALoadableFileExtension(const c8* fileName) const
|
|||||||
//! returns true if the file maybe is able to be loaded by this class
|
//! returns true if the file maybe is able to be loaded by this class
|
||||||
bool CImageLoaderBLP::isALoadableFileFormat(io::IReadFile* file) const
|
bool CImageLoaderBLP::isALoadableFileFormat(io::IReadFile* file) const
|
||||||
{
|
{
|
||||||
// std::cout <<"Checking if file is a BLP file\n";
|
//Checking if file is a BLP file
|
||||||
if (!file)
|
if (!file)
|
||||||
{
|
{
|
||||||
DEBUG(std::cout<<"No such file: "<<file->getFileName()<<"\n");
|
DEBUG(logdebug("No such file: %s",file->getFileName()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
std::string fileId;
|
std::string fileId;
|
||||||
// Read the first few bytes of the BLP file
|
// Read the first few bytes of the BLP file
|
||||||
if (file->read(&fileId[0], 4) != 4)
|
if (file->read(&fileId[0], 4) != 4)
|
||||||
{
|
{
|
||||||
DEBUG(std::cout << "Cannot read BLP file header\n");
|
DEBUG(logdebug("Cannot read BLP file header\n"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fileId[0]=='B' && fileId[1]=='L' && fileId[2]=='P' && fileId[3]=='2')
|
if(fileId[0]=='B' && fileId[1]=='L' && fileId[2]=='P' && fileId[3]=='2')
|
||||||
{
|
{
|
||||||
DEBUG(std::cout << "Header is BLP2, file should be loadable\n");
|
DEBUG(logdebug("Header is BLP2, file should be loadable"));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DEBUG(std::cout << "Header doesn't match, this is no BLP file\n");
|
DEBUG(logdebug("Header doesn't match, this is no BLP file"));
|
||||||
DEBUG(std::cout << "Expected:BLP2 Got:"<<fileId.c_str()<<"\n");
|
DEBUG(logdebug("Expected:BLP2 Got:%s",fileId.c_str()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "CM2MeshFileLoader.h"
|
#include "CM2MeshFileLoader.h"
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
#define DEBUG(code) code;
|
#define DEBUG(code) code;
|
||||||
@ -49,10 +50,9 @@ file->read(&header,sizeof(ModelHeader));
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DEBUG(logger->log(L"header okay",ELL_INFORMATION));
|
DEBUG(logdebug("header okay"));
|
||||||
}
|
}
|
||||||
//Name -> not very important I think, but save it nontheless;
|
//Name -> not very important I think, but save it nontheless;
|
||||||
DEBUG(std::cout << "Name offset:" << header.nameOfs << "Name length:" << header.nameLength << "\n");
|
|
||||||
//M2MeshName.clear();
|
//M2MeshName.clear();
|
||||||
//M2MeshName.reserve(header.nameLength);
|
//M2MeshName.reserve(header.nameLength);
|
||||||
file->seek(header.nameOfs);
|
file->seek(header.nameOfs);
|
||||||
@ -73,7 +73,7 @@ for(u32 i =0;i<header.nVertices;i++)
|
|||||||
file->read(&tempM2MVert,sizeof(ModelVertex));
|
file->read(&tempM2MVert,sizeof(ModelVertex));
|
||||||
M2MVertices.push_back(tempM2MVert);
|
M2MVertices.push_back(tempM2MVert);
|
||||||
}
|
}
|
||||||
DEBUG(std::cout << "Read "<<M2MVertices.size()<<"/"<<header.nVertices<<" Vertices\n");
|
DEBUG(logdebug("Read %u/%u Vertices",M2MVertices.size(),header.nVertices));
|
||||||
|
|
||||||
//Views == Sets of vertices. Usage yet unknown. Global data
|
//Views == Sets of vertices. Usage yet unknown. Global data
|
||||||
if(M2MViews.size()>0)
|
if(M2MViews.size()>0)
|
||||||
@ -87,8 +87,8 @@ for(u32 i =0;i<header.nViews;i++)
|
|||||||
}
|
}
|
||||||
//std::cout << "Read "<<M2MViews.size()<<"/"<<header.nViews<<" Views\n";
|
//std::cout << "Read "<<M2MViews.size()<<"/"<<header.nViews<<" Views\n";
|
||||||
|
|
||||||
DEBUG(logger->log("Using View 0 for all further operations",ELL_INFORMATION));
|
DEBUG(logdebug("Using View 0 for all further operations"));
|
||||||
DEBUG(std::cout<<"This View has "<<M2MViews[0].nSub<<" Submeshes\n");
|
DEBUG(logdebug("This View has %u Submeshes",M2MViews[0].nSub));
|
||||||
|
|
||||||
//Vertex indices of a specific view.Local to View 0
|
//Vertex indices of a specific view.Local to View 0
|
||||||
if(M2MIndices.size()>0)
|
if(M2MIndices.size()>0)
|
||||||
@ -101,7 +101,7 @@ for(u32 i =0;i<M2MViews[0].nIndex;i++)
|
|||||||
file->read(&tempM2Index,sizeof(u16));
|
file->read(&tempM2Index,sizeof(u16));
|
||||||
M2MIndices.push_back(tempM2Index);
|
M2MIndices.push_back(tempM2Index);
|
||||||
}
|
}
|
||||||
DEBUG(std::cout << "Read "<<M2MIndices.size()<<"/"<<M2MViews[0].nIndex<<" Indices\n");
|
DEBUG(logdebug("Read %u/%u Indices",M2MIndices.size(),M2MViews[0].nIndex));
|
||||||
|
|
||||||
|
|
||||||
//Triangles. Data Points point to the Vertex Indices, not the vertices themself. 3 Points = 1 Triangle, Local to View 0
|
//Triangles. Data Points point to the Vertex Indices, not the vertices themself. 3 Points = 1 Triangle, Local to View 0
|
||||||
@ -115,8 +115,7 @@ for(u32 i =0;i<M2MViews[0].nTris;i++)
|
|||||||
file->read(&tempM2Triangle,sizeof(u16));
|
file->read(&tempM2Triangle,sizeof(u16));
|
||||||
M2MTriangles.push_back(tempM2Triangle);
|
M2MTriangles.push_back(tempM2Triangle);
|
||||||
}
|
}
|
||||||
DEBUG(std::cout << "Read "<<M2MTriangles.size()<<"/"<<M2MViews[0].nTris<<" Triangle Indices\n");
|
DEBUG(logdebug("Read %u/%u Triangles",M2MTriangles.size(),M2MViews[0].nTris));
|
||||||
|
|
||||||
//Submeshes, Local to View 0
|
//Submeshes, Local to View 0
|
||||||
if(M2MSubmeshes.size()>0)
|
if(M2MSubmeshes.size()>0)
|
||||||
M2MSubmeshes.clear();
|
M2MSubmeshes.clear();
|
||||||
@ -129,7 +128,7 @@ for(u32 i =0;i<M2MViews[0].nSub;i++)
|
|||||||
M2MSubmeshes.push_back(tempM2Submesh);
|
M2MSubmeshes.push_back(tempM2Submesh);
|
||||||
// std::cout<< "Submesh " <<i<<" ID "<<tempM2Submesh.meshpartId<<" starts at V/T "<<tempM2Submesh.ofsVertex<<"/"<<tempM2Submesh.ofsTris<<" and has "<<tempM2Submesh.nVertex<<"/"<<tempM2Submesh.nTris<<" V/T\n";
|
// std::cout<< "Submesh " <<i<<" ID "<<tempM2Submesh.meshpartId<<" starts at V/T "<<tempM2Submesh.ofsVertex<<"/"<<tempM2Submesh.ofsTris<<" and has "<<tempM2Submesh.nVertex<<"/"<<tempM2Submesh.nTris<<" V/T\n";
|
||||||
}
|
}
|
||||||
DEBUG(std::cout << "Read "<<M2MSubmeshes.size()<<"/"<<M2MViews[0].nSub<<" Submeshes\n");
|
DEBUG(logdebug("Read %u/%u Submeshes",M2MSubmeshes.size(),M2MViews[0].nSub));
|
||||||
|
|
||||||
//Texture units. Local to view 0
|
//Texture units. Local to view 0
|
||||||
TextureUnit tempM2TexUnit;
|
TextureUnit tempM2TexUnit;
|
||||||
@ -143,7 +142,7 @@ for(u32 i=0;i<M2MViews[0].nTex;i++)
|
|||||||
file->read(&tempM2TexUnit,sizeof(TextureUnit));
|
file->read(&tempM2TexUnit,sizeof(TextureUnit));
|
||||||
M2MTextureUnit.push_back(tempM2TexUnit);
|
M2MTextureUnit.push_back(tempM2TexUnit);
|
||||||
}
|
}
|
||||||
DEBUG(std::cout << "Read "<<M2MTextureUnit.size()<<" Texture Unit entries for View 0\n");
|
DEBUG(logdebug("Read %u Texture Unit entries for View 0",M2MTextureUnit.size()));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -160,7 +159,7 @@ for(u32 i=0;i<header.nTexLookup;i++)
|
|||||||
file->read(&tempM2TexLookup,sizeof(u16));
|
file->read(&tempM2TexLookup,sizeof(u16));
|
||||||
M2MTextureLookup.push_back(tempM2TexLookup);
|
M2MTextureLookup.push_back(tempM2TexLookup);
|
||||||
}
|
}
|
||||||
DEBUG(std::cout << "Read "<<M2MTextureLookup.size()<<" Texture lookup entries\n");
|
DEBUG(logdebug("Read %u Texture lookup entries",M2MTextureLookup.size()));
|
||||||
|
|
||||||
//Texture Definitions table. This is global data
|
//Texture Definitions table. This is global data
|
||||||
TextureDefinition tempM2TexDef;
|
TextureDefinition tempM2TexDef;
|
||||||
@ -174,7 +173,7 @@ for(u32 i=0;i<header.nTextures;i++)
|
|||||||
file->read(&tempM2TexDef,sizeof(TextureDefinition));
|
file->read(&tempM2TexDef,sizeof(TextureDefinition));
|
||||||
M2MTextureDef.push_back(tempM2TexDef);
|
M2MTextureDef.push_back(tempM2TexDef);
|
||||||
}
|
}
|
||||||
DEBUG(std::cout << "Read "<<M2MTextureDef.size()<<" Texture Definition entries\n");
|
DEBUG(logdebug("Read %u Texture Definition entries",M2MTextureDef.size()));
|
||||||
|
|
||||||
//Render Flags table. This is global data
|
//Render Flags table. This is global data
|
||||||
RenderFlags tempM2RF;
|
RenderFlags tempM2RF;
|
||||||
@ -188,7 +187,7 @@ for(u32 i=0;i<header.nTexFlags;i++)
|
|||||||
file->read(&tempM2RF,sizeof(RenderFlags));
|
file->read(&tempM2RF,sizeof(RenderFlags));
|
||||||
M2MRenderFlags.push_back(tempM2RF);
|
M2MRenderFlags.push_back(tempM2RF);
|
||||||
}
|
}
|
||||||
DEBUG(std::cout << "Read "<<M2MRenderFlags.size()<<" Render Flags\n");
|
DEBUG(logdebug("Read %u Renderflags",M2MRenderFlags.size()));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -204,7 +203,6 @@ for(u32 i=0; i<M2MTextureDef.size(); i++)
|
|||||||
tempTexFileName.reserve(M2MTextureDef[i].texFileLen + 1);
|
tempTexFileName.reserve(M2MTextureDef[i].texFileLen + 1);
|
||||||
file->seek(M2MTextureDef[i].texFileOfs);
|
file->seek(M2MTextureDef[i].texFileOfs);
|
||||||
file->read((void*)tempTexFileName.c_str(),M2MTextureDef[i].texFileLen);
|
file->read((void*)tempTexFileName.c_str(),M2MTextureDef[i].texFileLen);
|
||||||
DEBUG(std::cout << "texture: '" << tempTexFileName << "'\n");
|
|
||||||
M2MTextureFiles.push_back(tempTexFileName.c_str());
|
M2MTextureFiles.push_back(tempTexFileName.c_str());
|
||||||
std::cout<<M2MTextureFiles.size()<<"-"<<M2MTextureFiles[i].c_str()<<"\n";
|
std::cout<<M2MTextureFiles.size()<<"-"<<M2MTextureFiles[i].c_str()<<"\n";
|
||||||
}
|
}
|
||||||
@ -277,7 +275,7 @@ std::transform(TexName.begin(), TexName.end(), TexName.begin(), tolower);
|
|||||||
IMB->getMaterial().setTexture(0,Device->getVideoDriver()->getTexture(TexName.c_str()));
|
IMB->getMaterial().setTexture(0,Device->getVideoDriver()->getTexture(TexName.c_str()));
|
||||||
if(i<M2MRenderFlags.size())
|
if(i<M2MRenderFlags.size())
|
||||||
{
|
{
|
||||||
DEBUG(std::cout<<M2MRenderFlags[i].flags<<"--"<<M2MRenderFlags[i].blending<<"\n");
|
DEBUG(logdebug("Render Flags: %u %u",M2MRenderFlags[i].flags,M2MRenderFlags[i].blending));
|
||||||
IMB->getMaterial().BackfaceCulling=(M2MRenderFlags[i].flags & 0x04)?false:true;
|
IMB->getMaterial().BackfaceCulling=(M2MRenderFlags[i].flags & 0x04)?false:true;
|
||||||
if(M2MRenderFlags[i].blending==1)
|
if(M2MRenderFlags[i].blending==1)
|
||||||
IMB->getMaterial().MaterialType=video::EMT_TRANSPARENT_ALPHA_CHANNEL;
|
IMB->getMaterial().MaterialType=video::EMT_TRANSPARENT_ALPHA_CHANNEL;
|
||||||
|
|||||||
@ -45,7 +45,7 @@ PseuGUI::PseuGUI()
|
|||||||
_guienv = NULL;
|
_guienv = NULL;
|
||||||
_scene = NULL;
|
_scene = NULL;
|
||||||
_passtime = _lastpasstime = _passtimediff = 0;
|
_passtime = _lastpasstime = _passtimediff = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
PseuGUI::~PseuGUI()
|
PseuGUI::~PseuGUI()
|
||||||
{
|
{
|
||||||
@ -126,7 +126,7 @@ void PseuGUI::_Init(void)
|
|||||||
_driver->addExternalImageLoader(BLPloader);
|
_driver->addExternalImageLoader(BLPloader);
|
||||||
scene::CM2MeshFileLoader* m2loader = new scene::CM2MeshFileLoader(_device, "./data/texture");
|
scene::CM2MeshFileLoader* m2loader = new scene::CM2MeshFileLoader(_device, "./data/texture");
|
||||||
_smgr->addExternalMeshLoader(m2loader);
|
_smgr->addExternalMeshLoader(m2loader);
|
||||||
|
_throttle=0;
|
||||||
_initialized = true;
|
_initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,6 +199,13 @@ void PseuGUI::Run(void)
|
|||||||
_guienv->drawAll(); // irr: draw gui elements
|
_guienv->drawAll(); // irr: draw gui elements
|
||||||
_scene->OnDraw(); // custom: draw everything that has to be draw late (post-processing also belongs here)
|
_scene->OnDraw(); // custom: draw everything that has to be draw late (post-processing also belongs here)
|
||||||
_driver->endScene(); // irr: drawing done
|
_driver->endScene(); // irr: drawing done
|
||||||
|
if(_driver->getFPS()>100 && _throttle < 10)//Primitive FPS-Limiter - upper cap hardcoded 100 FPS.
|
||||||
|
_throttle++; //lowercap 60 (if it drops below, limiting is eased).
|
||||||
|
if(_driver->getFPS()<60 && _throttle>0) //but honestly, a 10 msec delay is not worth this amount of code.
|
||||||
|
_throttle--; //If the FPS is down, it will never be because of this
|
||||||
|
if(_throttle>0) //Thus i opt for dropping the charade and using a fixed conf value of max 10.
|
||||||
|
_device->sleep(_throttle); //sleeps max 10 msec (=_throttle) here.
|
||||||
|
|
||||||
}
|
}
|
||||||
catch(...)
|
catch(...)
|
||||||
{
|
{
|
||||||
@ -268,6 +275,7 @@ void PseuGUI::_UpdateSceneState(void)
|
|||||||
switch (_scenestate)
|
switch (_scenestate)
|
||||||
{
|
{
|
||||||
case SCENESTATE_GUISTART: _scene = new SceneGuiStart(this); break;
|
case SCENESTATE_GUISTART: _scene = new SceneGuiStart(this); break;
|
||||||
|
case SCENESTATE_LOGINSCREEN: _scene = new SceneLogin(this); break;
|
||||||
case SCENESTATE_WORLD: _scene = new SceneWorld(this); break;
|
case SCENESTATE_WORLD: _scene = new SceneWorld(this); break;
|
||||||
default: _scene = new Scene(this); // will draw nothing, just yield the gui
|
default: _scene = new Scene(this); // will draw nothing, just yield the gui
|
||||||
}
|
}
|
||||||
@ -277,6 +285,7 @@ void PseuGUI::_UpdateSceneState(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// used to get our current WorldPosition
|
// used to get our current WorldPosition
|
||||||
WorldPosition PseuGUI::GetWorldPosition(void)
|
WorldPosition PseuGUI::GetWorldPosition(void)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -31,7 +31,7 @@ enum DriverIDs
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define MOUSE_SENSIVITY 0.5f
|
#define MOUSE_SENSIVITY 0.5f
|
||||||
#define ANGLE_STEP (M_PI/180.0f)
|
#define ANGLE_STEP (M_PI/180.0f)
|
||||||
#define DEG_TO_RAD(x) ((x)*ANGLE_STEP)
|
#define DEG_TO_RAD(x) ((x)*ANGLE_STEP)
|
||||||
#define RAD_TO_DEG(x) ((x)/ANGLE_STEP)
|
#define RAD_TO_DEG(x) ((x)/ANGLE_STEP)
|
||||||
#define RAD_FIX(x) ( (x)>(2*M_PI) ? ((x)-(2*M_PI)) : ( ((x)<0) ? ((x)+(2*M_PI)) : (x) ) )
|
#define RAD_FIX(x) ( (x)>(2*M_PI) ? ((x)-(2*M_PI)) : ( ((x)<0) ? ((x)+(2*M_PI)) : (x) ) )
|
||||||
@ -64,10 +64,11 @@ private:
|
|||||||
|
|
||||||
class PseuGUI
|
class PseuGUI
|
||||||
{
|
{
|
||||||
// too bad friends are not inherited...
|
// too bad friends are not inherited...
|
||||||
friend class Scene;
|
friend class Scene;
|
||||||
friend class SceneWorld;
|
friend class SceneWorld;
|
||||||
friend class SceneGuiStart;
|
friend class SceneGuiStart;
|
||||||
|
friend class SceneLogin;
|
||||||
// ...
|
// ...
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -117,6 +118,7 @@ private:
|
|||||||
irr::ITimer *_timer;
|
irr::ITimer *_timer;
|
||||||
uint32 _passtime, _lastpasstime, _passtimediff;
|
uint32 _passtime, _lastpasstime, _passtimediff;
|
||||||
irr::core::dimension2d<irr::s32> _screendimension;
|
irr::core::dimension2d<irr::s32> _screendimension;
|
||||||
|
uint32 _throttle;//used for frameratelimiting
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -26,7 +26,7 @@ public:
|
|||||||
virtual void OnUpdate(s32);
|
virtual void OnUpdate(s32);
|
||||||
virtual void OnDraw(void);
|
virtual void OnDraw(void);
|
||||||
virtual void OnDrawBegin(void);
|
virtual void OnDrawBegin(void);
|
||||||
virtual void OnDelete(void);
|
virtual void OnDelete(void);
|
||||||
virtual video::SColor GetBackgroundColor(void);
|
virtual video::SColor GetBackgroundColor(void);
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@ -48,7 +48,22 @@ private:
|
|||||||
IGUIImage *irrlogo, *driverlogo;
|
IGUIImage *irrlogo, *driverlogo;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class GUIEventReceiver;
|
||||||
|
|
||||||
|
class SceneLogin : public Scene
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SceneLogin(PseuGUI *gui);
|
||||||
|
void OnUpdate(s32);
|
||||||
|
void OnDelete(void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
gui::IGUIElement* root;
|
||||||
|
IGUIImage *irrlogo, *driverlogo;
|
||||||
|
GUIEventReceiver *eventrecv;
|
||||||
|
PseuGUI* _gui;
|
||||||
|
};
|
||||||
|
|
||||||
class ShTlTerrainSceneNode;
|
class ShTlTerrainSceneNode;
|
||||||
class MCameraFPS;
|
class MCameraFPS;
|
||||||
|
|||||||
98
src/Client/GUI/SceneLogin.cpp
Normal file
98
src/Client/GUI/SceneLogin.cpp
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
#include "common.h"
|
||||||
|
#include "PseuGUI.h"
|
||||||
|
#include "PseuWoW.h"
|
||||||
|
#include "Scene.h"
|
||||||
|
#include "RealmSession.h"
|
||||||
|
|
||||||
|
enum GuiElementID
|
||||||
|
{
|
||||||
|
TEXTBOX_NAME = 0x1,
|
||||||
|
TEXTBOX_PASSWORD = 0x2,
|
||||||
|
BUTTON_QUIT = 0x4,
|
||||||
|
BUTTON_COMMUNITY = 0x8,
|
||||||
|
BUTTON_LOGON = 0x10,
|
||||||
|
};
|
||||||
|
|
||||||
|
class GUIEventReceiver : public IEventReceiver
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
GUIEventReceiver()
|
||||||
|
{
|
||||||
|
buttons=0;
|
||||||
|
}
|
||||||
|
virtual bool OnEvent(const SEvent& event)
|
||||||
|
{
|
||||||
|
//GUI EVENT
|
||||||
|
if (event.EventType == EET_GUI_EVENT)
|
||||||
|
{
|
||||||
|
s32 id = event.GUIEvent.Caller->getID();
|
||||||
|
|
||||||
|
switch(event.GUIEvent.EventType)
|
||||||
|
{
|
||||||
|
case EGET_BUTTON_CLICKED:
|
||||||
|
logdebug("user clicked button %u",id);
|
||||||
|
buttons+=id;
|
||||||
|
return true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
u32 buttons;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//TODO: Reposition elements on resize
|
||||||
|
|
||||||
|
SceneLogin::SceneLogin(PseuGUI *gui) : Scene(gui)
|
||||||
|
{
|
||||||
|
_gui=gui;
|
||||||
|
eventrecv = new GUIEventReceiver();
|
||||||
|
device->setEventReceiver(eventrecv);
|
||||||
|
root = guienv->getRootGUIElement();
|
||||||
|
|
||||||
|
dimension2d<s32> scrn = driver->getScreenSize();
|
||||||
|
|
||||||
|
irrlogo = guienv->addImage(driver->getTexture("data/misc/irrlichtlogo.png"), core::position2d<s32>(5,5));
|
||||||
|
guienv->addStaticText(L"Password:",rect<s32>((scrn.Width*0.5f)-90, (scrn.Height*0.3f)-10, (scrn.Width*0.5f)+90, (scrn.Height*0.3f)-10), false, false, 0, 0);
|
||||||
|
guienv->addStaticText(L"Account:", rect<s32>((scrn.Width*0.5f)-90, (scrn.Height*0.3f)+50, (scrn.Width*0.5f)+90, (scrn.Height*0.3f)+70), false, false, 0, 0);
|
||||||
|
guienv->addEditBox(L"", rect<s32>((scrn.Width*0.5f)-90, (scrn.Height*0.3f)+10, (scrn.Width*0.5f)+90, (scrn.Height*0.3f)+30), true, 0, 1);
|
||||||
|
guienv->addEditBox(L"", rect<s32>((scrn.Width*0.5f)-90, (scrn.Height*0.3f)+70, (scrn.Width*0.5f)+90, (scrn.Height*0.3f)+90), true, 0, 2)->setPasswordBox(true);
|
||||||
|
guienv->addButton(rect<s32>(scrn.Width-120, scrn.Height-40, scrn.Width-10, scrn.Height-10), 0, 4, L"Quit");
|
||||||
|
guienv->addButton(rect<s32>(10, scrn.Height-40, 120, scrn.Height-10), 0, 8, L"Community Site");
|
||||||
|
guienv->addButton(rect<s32>((scrn.Width*0.5f)-60, (scrn.Height*0.3f)+100, (scrn.Width*0.5f)+60, (scrn.Height*0.3f)+130), 0, 16, L"Logon");
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneLogin::OnUpdate(s32 timepassed)
|
||||||
|
{
|
||||||
|
if(eventrecv->buttons & BUTTON_QUIT)
|
||||||
|
{
|
||||||
|
_gui->Shutdown();
|
||||||
|
_gui->GetInstance()->Stop();
|
||||||
|
eventrecv->buttons=0;
|
||||||
|
}
|
||||||
|
if(eventrecv->buttons & BUTTON_LOGON)
|
||||||
|
{
|
||||||
|
logdebug("Commencing Logon");
|
||||||
|
core::stringc tmp;
|
||||||
|
tmp=root->getElementFromId(TEXTBOX_NAME,true)->getText();
|
||||||
|
std::string accname =tmp.c_str();
|
||||||
|
tmp=root->getElementFromId(TEXTBOX_PASSWORD,true)->getText();
|
||||||
|
std::string accpass=tmp.c_str();
|
||||||
|
logdebug("Trying to set Logon Data %u, %u", accname.size(), accpass.size());
|
||||||
|
_gui->GetInstance()->GetRSession()->SetLogonData(accname,accpass);
|
||||||
|
_gui->GetInstance()->GetRSession()->SendLogonChallenge();
|
||||||
|
eventrecv->buttons=0;
|
||||||
|
_gui->GetInstance()->login=true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SceneLogin::OnDelete(void)
|
||||||
|
{
|
||||||
|
// not necessary to delete the images, because they are deleted by guienv->clear()
|
||||||
|
}
|
||||||
|
|
||||||
@ -157,6 +157,8 @@ bool PseuInstance::Init(void)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
login=false;//No GUI Login attempted yet
|
||||||
|
|
||||||
log("Init complete.");
|
log("Init complete.");
|
||||||
_initialized=true;
|
_initialized=true;
|
||||||
return true;
|
return true;
|
||||||
@ -227,7 +229,18 @@ void PseuInstance::Run(void)
|
|||||||
// then try to connect
|
// then try to connect
|
||||||
_rsession = new RealmSession(this);
|
_rsession = new RealmSession(this);
|
||||||
_rsession->Connect();
|
_rsession->Connect();
|
||||||
_rsession->SendLogonChallenge();
|
|
||||||
|
if(!GetConf()->enablegui||!(GetConf()->accname.empty()||GetConf()->accpass.empty()))
|
||||||
|
{
|
||||||
|
logdebug("GUI not active or Login data pre-entered, skipping Login GUI");
|
||||||
|
|
||||||
|
_rsession->SetLogonData();
|
||||||
|
_rsession->SendLogonChallenge();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GetGUI()->SetSceneState(SCENESTATE_LOGINSCREEN);
|
||||||
|
}
|
||||||
|
|
||||||
// this is the mainloop
|
// this is the mainloop
|
||||||
while(!_stop)
|
while(!_stop)
|
||||||
@ -294,16 +307,25 @@ void PseuInstance::Update()
|
|||||||
_wsession->Start();
|
_wsession->Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we have no active sessions, we may reconnect
|
// if we have no active sessions, we may reconnect, if no GUI is active for login
|
||||||
if((!_rsession) && (!_wsession) && GetConf()->reconnect)
|
if((!_rsession) && (!_wsession) && GetConf()->reconnect && !(login||GetConf()->enablegui))
|
||||||
{
|
{
|
||||||
logdetail("Waiting %u ms before reconnecting.",GetConf()->reconnect);
|
logdetail("Waiting %u ms before reconnecting.",GetConf()->reconnect);
|
||||||
for(uint32 t = 0; t < GetConf()->reconnect && !this->Stopped(); t+=100) Sleep(100);
|
for(uint32 t = 0; t < GetConf()->reconnect && !this->Stopped(); t+=100) Sleep(100);
|
||||||
this->Sleep(1000); // wait 1 sec before reconnecting
|
this->Sleep(1000); // wait 1 sec before reconnecting
|
||||||
_rsession = new RealmSession(this);
|
_rsession = new RealmSession(this);
|
||||||
_rsession->Connect();
|
_rsession->Connect();
|
||||||
|
_rsession->SetLogonData();
|
||||||
_rsession->SendLogonChallenge(); // and login again
|
_rsession->SendLogonChallenge(); // and login again
|
||||||
}
|
}
|
||||||
|
if((!_rsession) && (!_wsession) && GetConf()->enablegui && login)
|
||||||
|
{
|
||||||
|
logdetail("Disconnected, switching GUI back to Loginscreen.");
|
||||||
|
_rsession = new RealmSession(this);
|
||||||
|
_rsession->Connect();
|
||||||
|
_gui->SetSceneState(SCENESTATE_LOGINSCREEN);
|
||||||
|
login=false;
|
||||||
|
}
|
||||||
|
|
||||||
// update currently existing/active sessions
|
// update currently existing/active sessions
|
||||||
if(_rsession)
|
if(_rsession)
|
||||||
|
|||||||
@ -104,6 +104,7 @@ public:
|
|||||||
|
|
||||||
void ProcessCliQueue(void);
|
void ProcessCliQueue(void);
|
||||||
void AddCliCommand(std::string);
|
void AddCliCommand(std::string);
|
||||||
|
bool login;//Set when GUI attempts to login
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|||||||
@ -295,6 +295,19 @@ void RealmSession::_HandleRealmList(ByteBuffer& pkt)
|
|||||||
GetInstance()->CreateWorldSession(); // will be done at next PseuInstance::Update()
|
GetInstance()->CreateWorldSession(); // will be done at next PseuInstance::Update()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RealmSession::SetLogonData(void)
|
||||||
|
{
|
||||||
|
_accname=GetInstance()->GetConf()->accname;
|
||||||
|
_accpass=GetInstance()->GetConf()->accpass;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RealmSession::SetLogonData(std::string accname, std::string accpass)
|
||||||
|
{
|
||||||
|
_accname=accname;
|
||||||
|
_accpass=accpass;
|
||||||
|
logdebug("Data Set");
|
||||||
|
}
|
||||||
|
|
||||||
void RealmSession::SendLogonChallenge(void)
|
void RealmSession::SendLogonChallenge(void)
|
||||||
{
|
{
|
||||||
if(!_socket)
|
if(!_socket)
|
||||||
@ -302,14 +315,14 @@ void RealmSession::SendLogonChallenge(void)
|
|||||||
logerror("Can't send logon challenge, socket doesn't exist");
|
logerror("Can't send logon challenge, socket doesn't exist");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if( GetInstance()->GetConf()->accname.empty() || GetInstance()->GetConf()->clientversion_string.empty()
|
if( _accname.empty() || GetInstance()->GetConf()->clientversion_string.empty()
|
||||||
|| GetInstance()->GetConf()->clientbuild==0 || GetInstance()->GetConf()->clientlang.empty() )
|
|| GetInstance()->GetConf()->clientbuild==0 || GetInstance()->GetConf()->clientlang.empty() )
|
||||||
{
|
{
|
||||||
logcritical("Missing data, can't send Login challenge to Realm Server! (check your conf files)");
|
logcritical("Missing data, can't send Login challenge to Realm Server! (check your conf files)");
|
||||||
GetInstance()->SetError();
|
GetInstance()->SetError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::string acc = stringToUpper(GetInstance()->GetConf()->accname);
|
std::string acc = stringToUpper(_accname);
|
||||||
ByteBuffer packet;
|
ByteBuffer packet;
|
||||||
packet << (uint8)AUTH_LOGON_CHALLENGE;
|
packet << (uint8)AUTH_LOGON_CHALLENGE;
|
||||||
packet << (uint8)6;
|
packet << (uint8)6;
|
||||||
@ -327,7 +340,7 @@ void RealmSession::SendLogonChallenge(void)
|
|||||||
packet.append(acc.c_str(),acc.length()); // append accname, skip \0
|
packet.append(acc.c_str(),acc.length()); // append accname, skip \0
|
||||||
|
|
||||||
SendRealmPacket(packet);
|
SendRealmPacket(packet);
|
||||||
|
logdebug("Packet Sent");
|
||||||
}
|
}
|
||||||
|
|
||||||
void RealmSession::_HandleLogonChallenge(ByteBuffer& pkt)
|
void RealmSession::_HandleLogonChallenge(ByteBuffer& pkt)
|
||||||
@ -346,10 +359,10 @@ void RealmSession::_HandleLogonChallenge(ByteBuffer& pkt)
|
|||||||
switch (lc.error)
|
switch (lc.error)
|
||||||
{
|
{
|
||||||
case 4:
|
case 4:
|
||||||
logerror("Realm Server did not find account \"%s\"!",GetInstance()->GetConf()->accname.c_str());
|
logerror("Realm Server did not find account \"%s\"!",_accname.c_str());
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
logerror("Account \"%s\" is already logged in!",GetInstance()->GetConf()->accname.c_str());
|
logerror("Account \"%s\" is already logged in!",_accname.c_str());
|
||||||
// TODO: wait a certain amount of time before reconnecting? conf option?
|
// TODO: wait a certain amount of time before reconnecting? conf option?
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
@ -362,8 +375,8 @@ void RealmSession::_HandleLogonChallenge(ByteBuffer& pkt)
|
|||||||
|
|
||||||
// now lets start calculating
|
// now lets start calculating
|
||||||
BigNumber N,A,B,a,u,x,v,S,salt,unk1,g,k(3); // init BNs, default k to 3
|
BigNumber N,A,B,a,u,x,v,S,salt,unk1,g,k(3); // init BNs, default k to 3
|
||||||
std::string user=stringToUpper( GetInstance()->GetConf()->accname );
|
std::string user=stringToUpper( _accname );
|
||||||
std::string _authstr=stringToUpper( user +":"+GetInstance()->GetConf()->accpass );
|
std::string _authstr=stringToUpper( user +":"+_accpass );
|
||||||
|
|
||||||
B.SetBinary(lc.B,32);
|
B.SetBinary(lc.B,32);
|
||||||
g.SetBinary(lc.g,lc.g_len);
|
g.SetBinary(lc.g,lc.g_len);
|
||||||
@ -435,7 +448,7 @@ void RealmSession::_HandleLogonChallenge(ByteBuffer& pkt)
|
|||||||
Nhash.UpdateBigNumbers(&N,NULL);
|
Nhash.UpdateBigNumbers(&N,NULL);
|
||||||
Nhash.Finalize();
|
Nhash.Finalize();
|
||||||
ghash.UpdateBigNumbers(&g,NULL);
|
ghash.UpdateBigNumbers(&g,NULL);
|
||||||
ghash.Finalize();
|
ghash.Finalize();
|
||||||
for(i=0;i<20;i++)Ng_hash[i] = Nhash.GetDigest()[i]^ghash.GetDigest()[i];
|
for(i=0;i<20;i++)Ng_hash[i] = Nhash.GetDigest()[i]^ghash.GetDigest()[i];
|
||||||
//printchex(Ng_hash,20,true);
|
//printchex(Ng_hash,20,true);
|
||||||
|
|
||||||
@ -467,7 +480,7 @@ void RealmSession::_HandleLogonChallenge(ByteBuffer& pkt)
|
|||||||
logdebug("--> CRC=%s",toHexDump((uint8*)crc_hash,20,false).c_str());
|
logdebug("--> CRC=%s",toHexDump((uint8*)crc_hash,20,false).c_str());
|
||||||
|
|
||||||
|
|
||||||
// now lets prepare the packet
|
// now lets prepare the packet
|
||||||
ByteBuffer packet;
|
ByteBuffer packet;
|
||||||
packet << (uint8)AUTH_LOGON_PROOF;
|
packet << (uint8)AUTH_LOGON_PROOF;
|
||||||
packet.append(A.AsByteArray(),A.GetNumBytes());
|
packet.append(A.AsByteArray(),A.GetNumBytes());
|
||||||
@ -519,7 +532,7 @@ void RealmSession::_HandleLogonProof(ByteBuffer& pkt)
|
|||||||
DieOrReconnect(true);
|
DieOrReconnect(true);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// cover all other cases. continue only if success.
|
// cover all other cases. continue only if success.
|
||||||
default:
|
default:
|
||||||
if(error != REALM_AUTH_SUCCESS)
|
if(error != REALM_AUTH_SUCCESS)
|
||||||
{
|
{
|
||||||
@ -529,7 +542,7 @@ void RealmSession::_HandleLogonProof(ByteBuffer& pkt)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sAuthLogonProof_S lp;
|
sAuthLogonProof_S lp;
|
||||||
pkt.read((uint8*)&lp, 26); // the compiler didnt like 'sizeof(sAuthLogonProof_S)', said it was 28
|
pkt.read((uint8*)&lp, 26); // the compiler didnt like 'sizeof(sAuthLogonProof_S)', said it was 28
|
||||||
@ -592,7 +605,7 @@ void RealmSession::_HandleTransferData(ByteBuffer& pkt)
|
|||||||
|
|
||||||
_transbuf.append(pkt.contents(),pkt.size()); // append everything to the transfer buffer, which may also store incomplete bytes from the packet before
|
_transbuf.append(pkt.contents(),pkt.size()); // append everything to the transfer buffer, which may also store incomplete bytes from the packet before
|
||||||
pkt.rpos(pkt.size()); // set rpos to the end of the packet to indicate that we used all data
|
pkt.rpos(pkt.size()); // set rpos to the end of the packet to indicate that we used all data
|
||||||
|
|
||||||
logdev("transbuf size=%u rpos=%u diff=%u",_transbuf.size(),_transbuf.rpos(),_transbuf.size() - _transbuf.rpos());
|
logdev("transbuf size=%u rpos=%u diff=%u",_transbuf.size(),_transbuf.rpos(),_transbuf.size() - _transbuf.rpos());
|
||||||
|
|
||||||
while( _transbuf.size() - _transbuf.rpos() >= 3) // 3 = sizeof(uint32)+sizeof(uint8)
|
while( _transbuf.size() - _transbuf.rpos() >= 3) // 3 = sizeof(uint32)+sizeof(uint8)
|
||||||
@ -619,7 +632,7 @@ void RealmSession::_HandleTransferData(ByteBuffer& pkt)
|
|||||||
printf("\r[%.2f%% done]",pct);
|
printf("\r[%.2f%% done]",pct);
|
||||||
_log_resetcolor(true);
|
_log_resetcolor(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// finalize file
|
// finalize file
|
||||||
|
|||||||
@ -16,7 +16,9 @@ public:
|
|||||||
void Connect(void);
|
void Connect(void);
|
||||||
void Update(void);
|
void Update(void);
|
||||||
PseuInstance *GetInstance(void);
|
PseuInstance *GetInstance(void);
|
||||||
void ClearSocket(void);
|
void ClearSocket(void);
|
||||||
|
void SetLogonData(void);
|
||||||
|
void SetLogonData(std::string, std::string);
|
||||||
void SendLogonChallenge(void);
|
void SendLogonChallenge(void);
|
||||||
bool MustDie(void);
|
bool MustDie(void);
|
||||||
void SetMustDie(void);
|
void SetMustDie(void);
|
||||||
@ -33,7 +35,7 @@ private:
|
|||||||
void SendRealmPacket(ByteBuffer&);
|
void SendRealmPacket(ByteBuffer&);
|
||||||
void DumpInvalidPacket(ByteBuffer&);
|
void DumpInvalidPacket(ByteBuffer&);
|
||||||
void DieOrReconnect(bool err = false);
|
void DieOrReconnect(bool err = false);
|
||||||
|
std::string _accname,_accpass;
|
||||||
SocketHandler _sh;
|
SocketHandler _sh;
|
||||||
PseuInstance *_instance;
|
PseuInstance *_instance;
|
||||||
ZThread::LockedQueue<ByteBuffer*,ZThread::FastMutex> pktQueue;
|
ZThread::LockedQueue<ByteBuffer*,ZThread::FastMutex> pktQueue;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user