Revision: 1496
          http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=1496&view=rev
Author:   rorthomas
Date:     2010-07-24 20:12:56 +0000 (Sat, 24 Jul 2010)

Log Message:
-----------
added MP gui improvement: slow download net quality warning, messaged by server.
added security fix for message length.

Modified Paths:
--------------
    trunk/source/main/RoRFrameListener.cpp
    trunk/source/main/RoRFrameListener.h
    trunk/source/main/gui_mp.cpp
    trunk/source/main/gui_mp.h
    trunk/source/main/network.cpp

Modified: trunk/source/main/RoRFrameListener.cpp
===================================================================
--- trunk/source/main/RoRFrameListener.cpp      2010-07-24 18:15:11 UTC (rev 
1495)
+++ trunk/source/main/RoRFrameListener.cpp      2010-07-24 20:12:56 UTC (rev 
1496)
@@ -756,6 +756,10 @@
 {
        for (int i=0; i<MAX_TRUCKS; i++) trucks[i]=0;
 
+       pthread_mutex_init(&mutex_data, NULL);
+       net_quality=0; 
+       net_quality_changed=false;
+
        thread_mode=THREAD_MONO;
        if (SETTINGS.getSetting("Threads")=="1 (Standard 
CPU)")thread_mode=THREAD_MONO;
        if (SETTINGS.getSetting("Threads")=="2 (Hyper-Threading or Dual core 
CPU)") thread_mode=THREAD_HT;
@@ -1181,7 +1185,7 @@
                LoadingWindow::get()->hide();
 
 #ifdef USE_SOCKETW
-               new GUI_Multiplayer(net);
+               new GUI_Multiplayer(net, cam);
                GUI_Multiplayer::getSingleton().update();
 #endif //USE_SOCKETW
 
@@ -7090,6 +7094,12 @@
                        checkRemoteStreamResultsChanged();
                        netcheckGUITimer=0;
                }
+
+               // update net quality icon
+               if(getNetQualityChanged())
+               {
+                       GUI_Multiplayer::getSingleton().update();
+               }
        }
 
        // updating mirrors fixes its shaking!
@@ -7322,7 +7332,7 @@
        {
 #ifdef USE_LUA
                if(lua) lua->framestep();
-#endif
+#endif //USE_LUA
                updateIO(dt);
 
                if(!isEmbedded)
@@ -7923,4 +7933,32 @@
                GUI_Multiplayer::getSingleton().update();
 #endif // USE_SOCKETW
 #endif // USE_MYGUI    
+}
+
+
+void RoRFrameListener::setNetQuality(int q)
+{
+       pthread_mutex_lock(&mutex_data);
+       net_quality = q;
+       net_quality_changed = true;
+       pthread_mutex_unlock(&mutex_data);
+}
+
+int RoRFrameListener::getNetQuality(bool ack)
+{
+       int res = 0;
+       pthread_mutex_lock(&mutex_data);
+       res = net_quality;
+       if(ack) net_quality_changed=false;
+       pthread_mutex_unlock(&mutex_data);
+       return res;
+}
+
+bool RoRFrameListener::getNetQualityChanged()
+{
+       bool res = false;
+       pthread_mutex_lock(&mutex_data);
+       res = net_quality_changed;
+       pthread_mutex_unlock(&mutex_data);
+       return res;
 }
\ No newline at end of file

Modified: trunk/source/main/RoRFrameListener.h
===================================================================
--- trunk/source/main/RoRFrameListener.h        2010-07-24 18:15:11 UTC (rev 
1495)
+++ trunk/source/main/RoRFrameListener.h        2010-07-24 20:12:56 UTC (rev 
1496)
@@ -389,6 +389,18 @@
        OverlayWrapper *getOverlayWrapper() { return ow; };
 
        Water *w;
+
+public:
+       // mutex'ed data
+       void setNetQuality(int q);
+       int getNetQuality(bool ack=false);
+       bool getNetQualityChanged();
+       pthread_mutex_t mutex_data;
+private:
+       int net_quality; 
+       bool net_quality_changed; 
+
+
 protected:
 
        HeatHaze *heathaze;

Modified: trunk/source/main/gui_mp.cpp
===================================================================
--- trunk/source/main/gui_mp.cpp        2010-07-24 18:15:11 UTC (rev 1495)
+++ trunk/source/main/gui_mp.cpp        2010-07-24 20:12:56 UTC (rev 1496)
@@ -43,8 +43,10 @@
        assert( ms_Singleton );  return ( *ms_Singleton );
 }
 
-GUI_Multiplayer::GUI_Multiplayer(Network *_net) : net(_net), msgwin(0)
+GUI_Multiplayer::GUI_Multiplayer(Network *_net, Ogre::Camera *cam) : 
net(_net), msgwin(0), mCamera(cam)
 {
+       lineheight=16;
+
        // tooltip window
        tooltipPanel = 
MyGUI::Gui::getInstance().createWidget<MyGUI::Widget>("PanelSmall", 0, 0, 200, 
20,  MyGUI::Align::Default, "ToolTip");
        tooltipText = 
tooltipPanel->createWidget<MyGUI::StaticText>("StaticText", 4, 2, 200, 16,  
MyGUI::Align::Default);
@@ -62,9 +64,23 @@
        msgtext->setEditStatic(true);
        msgwin->setVisible(false);
 
+
+       // network quality warning
+       netmsgwin = 
MyGUI::Gui::getInstance().createWidget<MyGUI::Window>("FlowContainer", 5, 30, 
300, 40,  MyGUI::Align::Default, "Main");
+       netmsgwin->setAlpha(0.8f);
+       MyGUI::StaticImagePtr nimg = 
netmsgwin->createWidget<MyGUI::StaticImage>("StaticImage", 0, 0, 16, 16,  
MyGUI::Align::Default, "Main");
+       nimg->setImageTexture("error.png");
+       netmsgtext = netmsgwin->createWidget<MyGUI::StaticText>("StaticText", 
18, 2, 300, 40,  MyGUI::Align::Default, "helptext");
+       netmsgtext->setCaption(_L("Slow  Network  Download"));
+       netmsgtext->setFontName("VeraMoBd");
+       netmsgtext->setTextColour(MyGUI::Colour::Red);
+       netmsgtext->setFontHeight(lineheight);
+       netmsgwin->setVisible(false);
+
+
        // now the main GUI
        MyGUI::IntSize gui_area = 
GUIManager::getSingleton().getGUI()->getViewSize();
-       int x=gui_area.width - 200, y=30, lineheight=16;
+       int x=gui_area.width - 200, y=30;
        mpPanel = 
MyGUI::Gui::getInstance().createWidget<MyGUI::Widget>("FlowContainer", x, y, 
200, gui_area.height,  MyGUI::Align::Default, "Main");
        mpPanel->setVisible(true);
 
@@ -273,6 +289,10 @@
        client_t clients[MAX_PEERS];
        int slotid = 0;
        
+       MyGUI::IntSize gui_area = 
GUIManager::getSingleton().getGUI()->getViewSize();
+       int x=gui_area.width - 200, y=30;
+       mpPanel->setPosition(x,y);
+
        // add local player to first slot always
        user_info_t *lu = net->getLocalUserData();
        updateSlot(&player_rows[slotid], lu, true);
@@ -307,6 +327,14 @@
                        row->userTruckOKRemoteImg->setVisible(false);
                }
        }
+       
+       if(eflsingleton && eflsingleton->getNetQuality(true) != 0)
+       {
+               netmsgwin->setVisible(true);
+       } else if(eflsingleton && eflsingleton->getNetQuality(true) == 0)
+       {
+               netmsgwin->setVisible(false);
+       }
        return 0;
 }
 
@@ -324,8 +352,8 @@
 
 void GUI_Multiplayer::clickInfoIcon(MyGUI::WidgetPtr sender)
 {
-       msgtext->setCaption("FOOBAR: "+sender->getUserString("info"));
-       msgwin->setVisible(true);
+       //msgtext->setCaption("FOOBAR: "+sender->getUserString("info"));
+       //msgwin->setVisible(true);
 }
 
 void GUI_Multiplayer::openToolTip(MyGUI::WidgetPtr sender, const 
MyGUI::ToolTipInfo &t)

Modified: trunk/source/main/gui_mp.h
===================================================================
--- trunk/source/main/gui_mp.h  2010-07-24 18:15:11 UTC (rev 1495)
+++ trunk/source/main/gui_mp.h  2010-07-24 20:12:56 UTC (rev 1496)
@@ -36,7 +36,7 @@
 class GUI_Multiplayer : public Ogre::Singleton< GUI_Multiplayer >, public 
MemoryAllocatedObject
 {
 public:
-       GUI_Multiplayer(Network *net);
+       GUI_Multiplayer(Network *net, Ogre::Camera *mCamera);
        ~GUI_Multiplayer();
        static GUI_Multiplayer& getSingleton(void);
        static GUI_Multiplayer* getSingletonPtr(void);
@@ -66,8 +66,13 @@
        void openToolTip(MyGUI::WidgetPtr sender, const MyGUI::ToolTipInfo &t);
        void clickUserGoIcon(MyGUI::WidgetPtr sender);
 
+       MyGUI::WindowPtr netmsgwin;
+       MyGUI::StaticTextPtr netmsgtext;
        
        void updateSlot(player_row_t *row, user_info_t *c, bool self);
+
+       Ogre::Camera *mCamera;
+       int lineheight;
 };
 
 #endif //GUI_MP_H__

Modified: trunk/source/main/network.cpp
===================================================================
--- trunk/source/main/network.cpp       2010-07-24 18:15:11 UTC (rev 1495)
+++ trunk/source/main/network.cpp       2010-07-24 20:12:56 UTC (rev 1496)
@@ -367,6 +367,12 @@
 
        // construct buffer
        const int msgsize = sizeof(header_t) + len;
+
+       if(msgsize >= MAX_MESSAGE_LENGTH)
+       {
+       return -2;
+       }
+
        char buffer[MAX_MESSAGE_LENGTH];
        memset(buffer, 0, MAX_MESSAGE_LENGTH);
        memcpy(buffer, (char *)&head, sizeof(header_t));
@@ -411,6 +417,11 @@
 
        memcpy(head, buffer, sizeof(header_t));
 
+       if(head->size >= MAX_MESSAGE_LENGTH)
+       {
+       return -3;
+       }
+
        if(head->size>0)
        {
                //read the rest
@@ -582,6 +593,15 @@
                        if(cs) cs->addReceivedPacket(header, buffer);
                        continue;
                }
+               else if(header.command == MSG2_NETQUALITY && header.source == 
-1)
+               {
+                       if(header.size != sizeof(int))
+                               continue;
+                       int quality = *(int *)buffer;
+                       if(eflsingleton)
+                               eflsingleton->setNetQuality(quality);
+                       continue;
+               }
                else if(header.command == MSG2_USER_LEAVE)
                {
                        if(header.source == (int)myuid)


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Rigsofrods-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel

Reply via email to