Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

USARBotAPI.ComConnection


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
class ComConnection extends Actor config(USARComServer);

var ComLink link1,link2;
var bool bInit;
var class<ComLink> CLclass;
var config bool bDebug;

function setUp(string id1,string id2)
{
    if(!bInit)
    {
        //Spawn two ComLink objects
        link1=spawn(CLclass,self);
        if(link1!=None)
        {
            link1.setUp(id1);
        }
        link2=spawn(CLclass,self);
        if(link2!=None)
        {
            link2.setUp(id2);
        }
        
        if(link1!=None && link2!=None)
            bInit=true;
        else
        {
            if(bDebug)
                log("ComConnection : Cannot spawn ComLink classes");
        }
    }
}

//Process the requests sent by the robot
function processMessage(string Msg, int Count, byte M[255], string id)
{
    local string Messg, MsgSplit, MsgEnd;
    local string cmdType;
    local int  i;
    
    MsgEnd=";";
    MsgSplit=" ";
    
    if(bDebug) log("ComConnection: "$Msg);
    
    //Removing end of message delim
    i=InStr(Msg,MsgEnd);
    if(i == -1)
    {
        i=Len(Msg);
        log("ComConnection: Recieved Message does not terminate well - "$Msg);
    }
    Msg=left(Msg,i);
    
    if(bDebug)
        log("ComConnection: After removing end of message limiter - "$Msg);

    //Splitting message	
    i=InStr(Msg,MsgSplit);
    if(i==-1)
        i=Len(Msg);
    cmdType=Left(Msg,i);
    cmdType = Caps(cmdType);
    Messg=Mid(Msg,i+1);
    
    //Processing the command
    switch(cmdType)
    {
        case "SEND":
            if(!(ComServer(Owner).isReachable(link1.id,link2.id)))
            {
                if(bDebug) log("ComServer: Lost connectivity between "$link1.id$" and "$link2.id);
                if(id==link1.id)
                {
                    link1.SendText("Fail: Lost connectivity between "$link1.id$" and "$link2.id$";");
                }
                else
                {
                    link2.SendText("Fail: Lost connectivity between "$link1.id$" and "$link2.id$";");
                }
                link1.Close();
                link2.Close();
                link1.bInit=false;
                link2.bInit=false;
                break;
            }
            if(id==link1.id)
            {
                link2.SendBinary(Count,M);
                link1.SendText("OK;");
            }
            else
            {
                link1.SendBinary(Count,M);
                link2.SendText("OK;");
            }
            break;
        case "CLOSE":
            link1.Close();
            link2.Close();
            link1.bInit=false;
            link2.bInit=false;
            break;
        //These should not occur
        case "REGISTER":
        case "LISTEN":
        case "OPEN":
        default:
            if(bDebug) log("ComConnection: Unknown message - "$Msg);
            if(id==link1.id)
            {
                Link1.SendText("Fail: Unknown message;");
            }
            else
            {
                Link2.SendText("Fail: Unknown message;");
            }
    }
}

defaultproperties
{
    CLclass=USARBotApi.ComLink
    bInit=false
    bDebug=true
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: Di 19.12.2006 19:17:22.000 - Creation time: Mo 16.4.2007 11:20:45.781 - Created with UnCodeX