New Lobby Awaiting Approval

Moderator: keyser

New Lobby Awaiting Approval

Postby Vicarian » 15 Apr 2013, 17:50

Xinnony and I have been working on this over the last week or so. He did most of the work and bounced ideas off me, while I fixed up bits of code here and there. Once Ze_PilOt approves changes for this, we'll see something like this when we load into the lobby. :D

newlobby.jpg
newlobby.jpg (205.72 KiB) Viewed 3796 times


ObserveStrings.jpg
ObserveStrings.jpg (224.65 KiB) Viewed 3661 times
Last edited by Vicarian on 16 Apr 2013, 23:01, edited 1 time in total.
User avatar
Vicarian
Avatar-of-War
 
Posts: 112
Joined: 19 Apr 2012, 08:43
Has liked: 0 time
Been liked: 1 time
FAF User Name: Vicarian

Re: New Lobby Awaiting Approval

Postby lextoc » 15 Apr 2013, 17:53

Looks nice! I'd leave the observer button next to the observers-allowed-box-thing tho

EDIT: also maybe put "Game speed" higher in the list so you can see it without scrolling down
I'm watching you!
User avatar
lextoc
Supreme Commander
 
Posts: 1057
Joined: 17 Mar 2013, 18:08
Has liked: 287 times
Been liked: 227 times
FAF User Name: lextoc

Re: New Lobby Awaiting Approval

Postby Combo » 15 Apr 2013, 18:00

Does auto-teams mean auto-balance? If so that would be a nice addition...
User avatar
Combo
Avatar-of-War
 
Posts: 92
Joined: 25 Nov 2012, 02:26
Has liked: 0 time
Been liked: 0 time
FAF User Name: theCombo

Re: New Lobby Awaiting Approval

Postby ZaphodX » 15 Apr 2013, 18:02

Nice work guys, we all appreciate it :)

Love the flags, just hope it doesn't encourage euro ping nazis or Brazilian haters.
User avatar
ZaphodX
Contributor
 
Posts: 560
Joined: 02 Jan 2013, 01:55
Location: UK, GMT+0
Has liked: 0 time
Been liked: 0 time
FAF User Name: TAG_ZaphodX

Re: New Lobby Awaiting Approval

Postby Vicarian » 15 Apr 2013, 20:10

Combo wrote:Does auto-teams mean auto-balance? If so that would be a nice addition...


The auto-balance function is in the code base, but it's currently bugged. I'm going to work on debugging it. Failing that, I'll just write a new one using the code Xinnony came up with to move players to different slots.

ZaphodX wrote:Nice work guys, we all appreciate it :)

Love the flags, just hope it doesn't encourage euro ping nazis or Brazilian haters.


Currently, there isn't anything stopping someone from tabbing out of the game and checking a player's country. We basically set the flags so people connected to the lobby would understand if someone has English as a second language.
Last edited by Vicarian on 15 Apr 2013, 20:13, edited 1 time in total.
User avatar
Vicarian
Avatar-of-War
 
Posts: 112
Joined: 19 Apr 2012, 08:43
Has liked: 0 time
Been liked: 1 time
FAF User Name: Vicarian

Re: New Lobby Awaiting Approval

Postby Xinnony » 15 Apr 2013, 20:11

And is not finished ;)

Edit : For see the changelog : https://bitbucket.org/thepilot/forged-a ... lobby/diff
User avatar
Xinnony
Contributor
 
Posts: 551
Joined: 19 Feb 2012, 02:49
Has liked: 70 times
Been liked: 34 times
FAF User Name: Xinnony

Re: New Lobby Awaiting Approval

Postby Vicarian » 15 Apr 2013, 20:14

Xinnony wrote:And is not finished ;)

Edit : For see the changelog : https://bitbucket.org/thepilot/forged-a ... lobby/diff


It's getting there, though. I'm on a crusade against obscenely long lines and for consistency in the code base, so our commits are getting hung up at the moment :P
User avatar
Vicarian
Avatar-of-War
 
Posts: 112
Joined: 19 Apr 2012, 08:43
Has liked: 0 time
Been liked: 1 time
FAF User Name: Vicarian

Re: New Lobby Awaiting Approval

Postby ColonelSheppard » 15 Apr 2013, 20:17

awesome!
(i have to take a new screenshot for the help i'm new thread)
User avatar
ColonelSheppard
Contributor
 
Posts: 2997
Joined: 20 Jul 2012, 12:54
Location: Germany
Has liked: 154 times
Been liked: 165 times
FAF User Name: Sheppy

Re: New Lobby Awaiting Approval

Postby Vicarian » 15 Apr 2013, 21:15

Also, for anyone working with the code base, I wrote a small application that reads through a text file you provide and spruces the file up (convert tabs to spaces, trim whitespace from the end of lines, etc). If you want to keep consistency, we have our lobby.lua set to a tab size of 4 spaces (the default in most editors). The current diff is giant, because of how inconsistent our week of work has made it, but hopefully it stays consistent from here on out.

trimmer.jpg
trimmer.jpg (37.87 KiB) Viewed 3730 times


The code, for the suspicious:

Code: Select all
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int option, sCount, seqCount, spacesPerTab, tabCount;
vector<string> lines;

string convertSpacesToTabs(int spacesPerTab, string str) {
    int curSpaceSeq;
    string spaces;
    // Get a string of spaces of length spacesPerTab
    for (int i = 0; i < spacesPerTab; i++) {
        spaces += " ";
    }
   
    // Try to find a space sequence in the string
    curSpaceSeq = str.find(spaces);
   
    while (curSpaceSeq > -1 ) {
        str = str.replace(curSpaceSeq, spaces.length(), "\t");
        curSpaceSeq = str.find(spaces);
        seqCount++;
    }
    return str;
}

string convertTabsToSpaces(int spacesPerTab, string str) {
    int currentTab;
    string spaces;
    // Get a string of spaces of length spacesPerTab
    for (int i = 0; i < spacesPerTab; i++) {
        spaces += " ";
    }
   
    // Try to find a tab in the string
    currentTab = str.find("\t");
    // Ensure tab is found, do the replacement
    if (tabCount > -1) {
        while (currentTab != -1) {
            str = str.replace(currentTab, 1, spaces);
            currentTab = str.find("\t");
            tabCount++;
        }
    }
    return str;
}

string trim(string str) {   
    int sLoc = str.find_last_of(' ');
    int lineSpaceCount = 0;
    int origStrLength = str.length();
    // If there is a space at the end of str, run the loop:
    while (sLoc == str.length() - 1 && sLoc != 0 && sLoc != -1) {
        str = str.substr(0, sLoc);
        sLoc = str.find_last_of(' ');
        lineSpaceCount++;
    }
    if (sLoc == 0 && lineSpaceCount == origStrLength - 1) {
        str = "";
        lineSpaceCount++;
    }
    sCount += lineSpaceCount;
    return str;
}

void readFile(char fn[]) {
    fstream FI(fn, fstream::in);
    string line;
    while (FI.good()) {
        getline(FI, line);
        line = trim(line);
        if (option == 1) {
            line = convertTabsToSpaces(spacesPerTab, line);
        } else if (option == 2) {
            line = convertSpacesToTabs(spacesPerTab, line);
        } else {
            cout << "You must choose option 1 or 2." << endl << "Option was: ";
            cout << option << endl;
        }
       
        lines.push_back(line);
    }
    cout << "File " << endl << "    " <<  fn << endl << "read successfully.";
    cout << endl;
    return;
}

void writeFile(char fn[]) {
    fstream FO(fn, fstream::out);
    for (vector<string>::iterator i = lines.begin(); i != lines.end(); i++) {
        FO << *i << endl;
    }
    cout << "File" << endl << "    " << fn << endl;
    cout << "written successfully." << endl;
}

int main() {
    char *fn;
    string fN;
   
    sCount = 0;
    option = 0;
    cout << "Enter the number of spaces per tab: ";
    cin >> spacesPerTab;
    cout << "Select an option:" << endl << "    1-Replace tabs with spaces";
    cout << endl << "    2-Replace spaces with tabs" << endl;
    cout << "Option: ";
    cin >> option;
    cout << "Enter a file name to read (can include path): " << endl;
    getline(cin, fN);
    getline(cin, fN);
    fn = (char*)fN.c_str();
    readFile(fn);
    if (sCount == 0 && tabCount == 0 && seqCount == 0) {
        cout << "There were no changes made to your file." << endl;
        cout << "You do not need to save a new file!" << endl;
    } else {
        cout << "Spaces removed: " << sCount << endl;
        if (option == 1) {
            cout << "Tabs replaced: " << tabCount << endl;
        } else if (option == 2) {
            cout << "Space sequences replaced: " << seqCount << endl;
        }
        cout << "End of processing." << endl << endl;
        cout << "Enter a file name to write to (can include path): " << endl;
        getline(cin, fN);
        fn = (char*)fN.c_str();
        writeFile(fn);
    }
   
    return 0;
}


EDIT: Fixed my derp with the trim() function (even better now) - thanks rootbeer.
EDIT (again): Debug strings are awesome.
EDIT (yet again): Adding missing MinGW compiler library
Attachments
filetrimmer.zip
(334.31 KiB) Downloaded 103 times
Last edited by Vicarian on 21 Apr 2013, 12:36, edited 5 times in total.
User avatar
Vicarian
Avatar-of-War
 
Posts: 112
Joined: 19 Apr 2012, 08:43
Has liked: 0 time
Been liked: 1 time
FAF User Name: Vicarian

Re: New Lobby Awaiting Approval

Postby rootbeer23 » 15 Apr 2013, 21:37

Code: Select all
   if (sLoc != -1) {
        while (sLoc == str.length() - 1) {
            str = str.substr(0, sLoc);
            sLoc = str.find_last_of(' ');
            sCount++;
        }
    }


this will fail for lines that consist only of spaces.
rootbeer23
Supreme Commander
 
Posts: 1001
Joined: 18 May 2012, 15:38
Has liked: 0 time
Been liked: 31 times
FAF User Name: root2342

Next

Return to FAF Suggestions

Who is online

Users browsing this forum: No registered users and 1 guest