1 (edited by jiks_p 2016-07-09 16:34:21)

Topic: New Redirection Tile ! On Map !

RedirectTile

hey Guys !
i made somthing for your Servers or Clients !
this is a Tile !
What ?? Tile ???
yeah !
This TILE can redirect your players to other server you have ! or other friends server !

how can add this to your server or client ?
its easy ...

Client Side :

Step 1 :

add this code to Chat.cpp

Chat.cpp
bool CChat::str_in_str(const char *chat, const char *pline)
{
    //int Length = str_length(chat);
    const char *pText = str_find_nocase(pline, chat);
    if (pText)
    {
        return true;
    }
    else
        return false;
}

Step 2 :

Add This code to Chat.h

Chat.h
virtual bool str_in_str(const char *chat, const char *pline);

Step 3 :
change this ->

Chat.cpp
if(ClientID == -1) // server message
        {
            str_copy(m_aLines[m_CurrentLine].m_aName, "*** ", sizeof(m_aLines[m_CurrentLine].m_aName));
            str_format(m_aLines[m_CurrentLine].m_aText, sizeof(m_aLines[m_CurrentLine].m_aText), "%s", pLine);
        }

to this :

Chat.cpp
if(ClientID == -1) // server message
        {
            str_copy(m_aLines[m_CurrentLine].m_aName, "*** ", sizeof(m_aLines[m_CurrentLine].m_aName));
            str_format(m_aLines[m_CurrentLine].m_aText, sizeof(m_aLines[m_CurrentLine].m_aText), "%s", pLine);
            if (str_in_str("RedirectTo:", pLine))
            {
                std::string s = pLine;
                string addr = s.substr(sizeof("RedirectTo:"),(s.length() - sizeof("RedirectTo:"))).c_str();
                str_copy(g_Config.m_UiServerAddress, addr, sizeof(g_Config.m_UiServerAddress));
                GameClient()->Client()->Connect(addr);
            }
        }

End ! now Your Client Can Join Any Server ! When Go to Redirect Tile



Server Side :

Step 1:

Character.cpp
#include <sstream>
#include <fstream>
std::string GetLine(int index)
{
    std::string TmpName = "";
    std::fstream f;
    f.open("ip.cfg", std::ios::in);
    if (!f.fail())
    {

        for (int i = 0; i < index; i++)
        {
            std::getline(f, TmpName);
        }
    }
    f.close();
    return TmpName.c_str();
}

Step 2:

find this code on Character.cpp :
int z = GameServer()->Collision()->IsTeleport(MapIndex);
and add this code , above of it :

Character.cpp
        int Redirect = GameServer()->Collision()->IsRedirect(MapIndex);
    if (Redirect)
    {
        std::string Cmd = "RedirectTo: " + GetLine(Redirect);
        GameServer()->SendChatTarget(GetPlayer()->GetCID(), Cmd.c_str());
    }

Step 3 :
add this code to collision.cpp

collision.cpp
int CCollision::IsRedirect(int Index)
{
    if (Index < 0 || !m_pTele)
        return 0;

    if (m_pTele[Index].m_Type == TILE_REDIRECT)
        return m_pTele[Index].m_Number;

    return 0;
}
collision.h
int IsRedirect(int Index);

Step 4 :
now you need add new Tile to Server :
add TILE_REDIRECT=1, to mapitem.h after TILE_TELECHECKIN,

Step 5 :
Replace This Line

collision.cpp
if (m_pTele && (m_pTele[Index].m_Type == TILE_TELEIN || m_pTele[Index].m_Type == TILE_TELEINEVIL || m_pTele[Index].m_Type == TILE_TELECHECKINEVIL || m_pTele[Index].m_Type == TILE_TELECHECK || m_pTele[Index].m_Type == TILE_TELECHECKIN))

with

collision.cpp
if (m_pTele && (m_pTele[Index].m_Type == TILE_REDIRECT || m_pTele[Index].m_Type == TILE_TELEIN || m_pTele[Index].m_Type == TILE_TELEINEVIL || m_pTele[Index].m_Type == TILE_TELECHECKINEVIL || m_pTele[Index].m_Type == TILE_TELECHECK || m_pTele[Index].m_Type == TILE_TELECHECKIN))

Step 6:

find all codes like

io.cpp
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_TELEIN;

and add this code  after it

io.cpp
else if (((CLayerTele*)pTiles)->m_pTeleTile[i].m_Type == TILE_REDIRECT)
((CLayerTiles*)pTiles)->m_pTiles[i].m_Index = TILE_REDIRECT;

Last Step :
Find this code

layer_tiles.cpp
if(pGrabbed->m_pTeleTile[y*pGrabbed->m_Width + x].m_Type == TILE_TELEIN || pGrabbed->m_pTeleTile[y*pGrabbed->m_Width+x].m_Type == TILE_TELEOUT || pGrabbed->m_pTeleTile[y*pGrabbed->m_Width+x].m_Type == TILE_TELEINEVIL || pGrabbed->m_pTeleTile[y*pGrabbed->m_Width+x].m_Type == TILE_TELECHECKINEVIL || pGrabbed->m_pTeleTile[y*pGrabbed->m_Width+x].m_Type == TILE_TELECHECK || pGrabbed->m_pTeleTile[y*pGrabbed->m_Width+x].m_Type == TILE_TELECHECKOUT || pGrabbed->m_pTeleTile[y*pGrabbed->m_Width+x].m_Type == TILE_TELECHECKIN || pGrabbed->m_pTeleTile[y*pGrabbed->m_Width+x].m_Type == TILE_TELEINWEAPON || pGrabbed->m_pTeleTile[y*pGrabbed->m_Width+x].m_Type == TILE_TELEINHOOK)

replace with this code

layer_tiles.cpp
if(pGrabbed->m_pTeleTile[y*pGrabbed->m_Width+x].m_Type == TILE_REDIRECT || pGrabbed->m_pTeleTile[y*pGrabbed->m_Width + x].m_Type == TILE_TELEIN || pGrabbed->m_pTeleTile[y*pGrabbed->m_Width+x].m_Type == TILE_TELEOUT || pGrabbed->m_pTeleTile[y*pGrabbed->m_Width+x].m_Type == TILE_TELEINEVIL || pGrabbed->m_pTeleTile[y*pGrabbed->m_Width+x].m_Type == TILE_TELECHECKINEVIL || pGrabbed->m_pTeleTile[y*pGrabbed->m_Width+x].m_Type == TILE_TELECHECK || pGrabbed->m_pTeleTile[y*pGrabbed->m_Width+x].m_Type == TILE_TELECHECKOUT || pGrabbed->m_pTeleTile[y*pGrabbed->m_Width+x].m_Type == TILE_TELECHECKIN || pGrabbed->m_pTeleTile[y*pGrabbed->m_Width+x].m_Type == TILE_TELEINWEAPON || pGrabbed->m_pTeleTile[y*pGrabbed->m_Width+x].m_Type == TILE_TELEINHOOK)

tada!
its done !

you must create new file "ip.cfg" in root of server.exe file
now as you use a teleport tile ! with number ! ( mapers know whats im saying ! )
you can use tele layer and use tile number 1 to create redirect tile on map !
but where is a Redirect ip ?  neutral
redirect ip's must write in ip.cfg file !
when you use Redirect Tile with number 3 ! Server Go to ip.cfg file ! and get line 3 of this file !
in the line 3 you must have a new ip:port of Redirection Server smile

2

Re: New Redirection Tile ! On Map !

Can you give us a situation where this would be used? or why one would want to be redirect to an other server?

Jesus is my Lord and Savior. Praise be unto God for giving us a way to live with him.

Check out my DeviantArt for all my TeeWorlds art and ideas for Teeoworlds

3

Re: New Redirection Tile ! On Map !

Seeing as this needs client modification I can't see much of a use for it, but nicely done!

Clan: Riot (I'm one of three leaders: Mile, Deku, pie)
Host teeworlds maps on a fng/ctf/dm/ddrace server for testing:http://riotproductions.tk/teewo/ broken-need reinstall nginx http://riotproductions.tk/bounce?whatEven, Teeworlds NA Discord chat

4

Re: New Redirection Tile ! On Map !

And only for DDNet (or DDRace?) based mods... but yeah thx for contribute!

5 (edited by 2016-07-10 07:44:31)

Re: New Redirection Tile ! On Map !

android272 wrote:

Can you give us a situation where this would be used? or why one would want to be redirect to an other server?

i think on ddrace modes you can have 4 kobra maps , when player go to end of kobra1 map ! auto connect to next Server with next kobra2 map with out change current map of server ! and other players , dont lose game !

unsigned char* wrote:

And only for DDNet (or DDRace?) based mods... but yeah thx for contribute!

ALL Mode can have it !

6

Re: New Redirection Tile ! On Map !

ofc! but your explanation is based on DDNet/DDRace sources...

7

Re: New Redirection Tile ! On Map !

unsigned char* wrote:

ofc! but your explanation is based on DDNet/DDRace sources...

other servers can have it !
servers like kog mode !
in the kog , players have a Level and power up !
they can playe in Special Server !
if players Reach to specific Level ! they can join new server of this mode !
if you create a level server , you can use this tile to send player to Next Server !

8

Re: New Redirection Tile ! On Map !

First of all, I really appreciate the idea, but is there a specific reason that the code is implemented in chat.cpp?

This feature seems more like an enginefeature to me, so it ppb. should be in engine/client or game/client.

But as it was already said, because this needs client modification (where's no way around it) the main part of the player will be able to use it unless it's implemented in vanilla or any popular client like DDNet.

Unless you do an epic mod which uses this feature so player will get your client smile

Greetings

"Panos."
               -FuroS