; F>c@spdZdkZdkZdkZdkZdkZdkZdkZdkZdk Z dZ dZ dZ dZ dZdZdZd Zd Zd Zd Zd ZdZdZdZdZeefZdZdZdZdZdZdZ dZ!dZ"dZ#eefZ$dfdYZ%dfdYZ&dfdYZ'd fd!YZ(d"Z)d#Z*d$Z+dS(%s,Code to start and maintain empire connectionNs0s1s2s3s4s5s6s7s8s9sasbscsdseiiiii i(i0i@iHs EmpIOQueuecBstZdZdZdZdZedZdZdZ dZ dZ d Z ed Z d Zd Zd ZdZdZdedZRS(sBroker all input and output to/from server. This class generally has only one instance associated with it. It is used mainly as a code/data container. cCsG|ad|_g|_d|_|_||_||_ t |_ dS(Nsi( sselfsempQueuesInpBufsFuncLists FLWaitLevs FLSentLevsasyncs defParserslogins loginParsers QU_OFFLINEsflags(sselfsasyncslogin((s@/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empQueue.pys__init__s   cCsti|ddjo,tid| |ti|d }ny|ii|dWnwtij o-}|i i tidt |n=t j o0}tidt ||iidnXdS(sImmediately send CMD to socket.s isSend error - embedded newline: sSocket write error: N(sstringsfindscmdsviewersErrorsselfssocketssendserrorses loginParsers Disconnectsstrs UnicodeError(sselfscmdse((s@/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empQueue.pysSendNows cGsdS(N((sargs((s@/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empQueue.pysdebugscCsb|djo d|GHnE|djo d|GHn+d|t|i|i|i|ifGHdS(Nssends## %ssgets-- %ss/%-30s @ len:%-2d wait:%-2d sent:%-2d flags:%-2d(stypesmsgslensselfsFuncLists FLWaitLevs FLSentLevsflags(sselfsmsgstype((s@/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empQueue.pysdebugXXs     cCsz|itjodSn|i}t|i|jp |djo t|_n&|i|di|i|i B|_dS(s@Set the queue flags depending on the current state of the queue.Nii( sselfsflagss QU_CONNECTINGs FLSentLevslsslensFuncListsQU_BURSTs postFlagsspreFlags(sselfsls((s@/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empQueue.pysdoFlagss # cCs=x6no.|i|i}|itj o|in|i}|tjo|id|_n|i ||id|_|tj o%|idi t jo|idi oH|id|_|i|i=d|id_ |idi i|n|i|itjp|it|ijoPqq WdS(sSend a command to the server.iiN(sselfsFuncLists FLSentLevsqElemssendingsNonescommandscmds FLWaitLevsSendNows __class__s NormalHandlers atSubPromptsoutsAnswersdoFlagssflagss QU_BURSTSslen(sselfsqElemscmd((s@/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empQueue.pys sendCommands&   5  )cCsxno|idjo |itjo|iny|idiWntnX|idit j oPn|id=|i d|_ |id|_|i oPqq WdS(Nii( sselfs FLSentLevsflagss QU_FULLSYNCs sendCommandsFuncListsstartsflashExceptionscommandsNones FLWaitLev(sself((s@/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empQueue.pys beginParsers    cCs xno|id}|itj o|in|i}|tj o|iidSn|i d|_ |i d|_ y|idi Wnt nX|id=|i d|_ |i d|_ |i o'y|i iWnt nXPqq WdS(s'Handle commands on queue when off-line.iiN(sselfsFuncListsqElemssendingsNonescommandscmds loginParsersConnects FLWaitLevs FLSentLevsstartsflashExceptions defParserslull(sselfscmdsqElem((s@/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empQueue.pysofflineSendCommand.s2        cCs||ijo|id|_n|i|=||ijoh|i|it|ijo0|itjp |itjo|i |ijo|i qndS(s)Forcibly remove a command from the queue.iN( spossselfs FLSentLevsFuncListsdoFlagsslensflagss QU_BURSTSsQU_SYNCs FLWaitLevs sendCommand(sselfspos((s@/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empQueue.pys popHandlerIs  LcCs.t|i}|i}|tjp ||jo |}n||jo |}n|ii||||ijo|i |i t jo|i q*|i t jp |i tjo|i|ijoU|i| o?|i|i o&y|iiWqtqXq"q&q*ndS(sAdd a command to the output queue. Normally, this will add a command to the end of the queue. However, it is possible to customize the location for the command via the pos argument. N(slensselfsFuncListsls FLSentLevspossNonesinsertshandlersdoFlagssflagss QU_OFFLINEsofflineSendCommands QU_BURSTSsQU_SYNCs FLWaitLevs sendCommands beginParsers defParserslullsflashException(sselfshandlerspossls FLSentLev((s@/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empQueue.pys AddHandlerXs*     3   cCsg}d}t} t}t}t} t }t }ti}ti}ti}|i}|i}|i}|i}|ii}d} xno|i!| jo_||i"4d|_"|_#|o|i$i%|n&|o |i!t&jo|i'nPny||gg|gd}|dod}|i$i)| n|d o| oPn| ny|d} Wn;tij o,}dt,|}|i$i)| nX| od }|i$i)| n|| d | } | o| d | jo| d} n|i#| |_#|i!|jo|i#|i"jo |n||}|| d ||)|||||<|d }|d =Wn| j onXx|o|d}|d=| o,y|i0i1|Wqt2qXqny|di1|Wnt2nX|d | jo@|d=|i#d|_#|i"d|_"|o|i3qmn|i!|joPqqWqW||_| o&y|i0i4Wqt2qXn$y|di4Wnt2nXd S( sParse input from socket; send all data to function list. This method does all the actual reading of the socket. It reads and stores the server information, and delegates complete lines of data to the data-managers. It also checks for the special sequence C_PROMPT which always indicates the end of a command. This method is made significantly more complex because of the heterogeneous mixture of command priorities. Tracking of FLWaitLev, and FLSentLev is an arduous task. ssInternal Breakiiis Exceptional condition on socket!isSocket read exception: sZero read on socket!s iN(5scacheserrorsC_PROMPTs_EmpIOQueue__C_PROMPTsQU_SYNCs_EmpIOQueue__QU_SYNCs QU_FULLSYNCs_EmpIOQueue__QU_FULLSYNCs QU_DISCONNECTs_EmpIOQueue__QU_DISCONNECTslens_EmpIOQueue__lensNones_EmpIOQueue__Nonesselectsselect__selectsstringscounts string__countssplits string__splitsselfsInpBufs self__InpBufsFuncListsself__FuncLists sendCommandsself__sendCommandssockets self__socketsrecvsself__socket__recvsStopReadsflagss FLSentLevs FLWaitLevs loginParsersErrors QU_OFFLINEsofflineSendCommandsstss Disconnectstmpsesstrscntslsdatas defParserslinesflashExceptions beginParserslull(sselfscaches string__counts_EmpIOQueue__lens self__InpBufs_EmpIOQueue__Nonesself__socket__recvs_EmpIOQueue__QU_SYNCsselect__selectstmpscnts_EmpIOQueue__C_PROMPTsStopReads_EmpIOQueue__QU_DISCONNECTsself__sendCommandsself__FuncListsstss self__socketsdatases_EmpIOQueue__QU_FULLSYNCslserrors string__split((s@/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empQueue.pys HandleInputws              #        cCs)|itjotSn|iiSdS(sReturn the socket descriptor.N(sselfsflagss QU_DISCONNECTsNonessocketsfileno(sself((s@/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empQueue.pysfilenoscCsd}|itjo>htd<td<td<td<td<|i}nt|i }|i }|djo|dt |}n|djo|d t |}n|djo d }n|Sd S( s1Return a string that describes the current queue.ss DisconnectedsOff-lines ConnectingsPauseds Logging inis s/sIdleN(smsgsselfsflagss QU_CONNECTINGs QU_DISCONNECTs QU_OFFLINEs QU_PAUSEDsQU_LOGINslensFuncListstots FLSentLevssentsstr(sselfstotsmsgssent((s@/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empQueue.pys GetStatusMsgs>    cCs.|i|i3|itjo t|_ndS(s8Permanently delete all commands that have not been sent.N(sselfsFuncLists FLSentLevsflagss QU_CONNECTINGsQU_BURST(sself((s@/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empQueue.pys clearQueues cCs|o>|itjo t|_q|itjo t|_qn|itjot|_|i|i t |i jo0|it jp |it jo|i|i jo'|i|i o|iqqn6|itjo%t|_|i o|iqndS(s,Pause/unpause all further outgoing commands.N(spausesselfsflagss QU_CONNECTINGs QU_PAUSEDs QU_OFFLINEs QU_DISCONNECTsQU_BURSTsdoFlagss FLSentLevslensFuncLists QU_BURSTSsQU_SYNCs FLWaitLevs sendCommands beginParsersofflineSendCommand(sselfspause((s@/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empQueue.pys pauseQueues"   L    icCsmt|i}|tjp ||jo |}nx3|i||!D]!}||}|o|SqDqDWdS(s9Execute a callback function on each element in the queue.N( slensselfsFuncListslsendsNonesstartsiscallbacksret(sselfscallbacksstartsendsislsret((s@/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empQueue.pys scanQueue/s  (s__name__s __module__s__doc__s__init__sSendNowsdebugsNonesdebugXXsdoFlagss sendCommands beginParsersofflineSendCommands popHandlers AddHandlers HandleInputsfilenos GetStatusMsgs clearQueues pauseQueues scanQueue(((s@/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empQueue.pys EmpIOQueues"             s LoginHandlercBsMtZdZdZdZdZdZdZdZdZ RS(s@Aid EmpIOQueue with all login/logout requests. This class requires the global viewer class to contain the class viewer.loginHandler. The class viewer.loginHandler must contain the following methods/objects: login_error(), login_success(), connect_success(), connect_terminate(), and login_kill cCsC||_||_d|_d|_||_t|_d|_dS(Nis( scallbacksselfs loginHandlers firstConnectssrcStartsusernames QU_FULLSYNCs postFlagsscommand(sselfscallbacksusername((s@/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empQueue.pys__init__Ds      cCs1tid}tiio|io!d|_|iiddSnyMt i t i t i t _ t i i dt i i|d|dfWnWt ij oH}|dtitifjo"|iidt|dSqnXd|_tt _|gt id*dt _dt _|iidS( s,Connect to specified host/port as coun/repr.sloginisEnter connect information.NshostsportsConnect error: i(sempDbsmegaDBsldbsDBIOs newDatabasesselfs firstConnectscallbacks login_errorssocketsAF_INETs SOCK_STREAMsempQueues setblockingsconnectserrorseserrnos EINPROGRESSs EWOULDBLOCKsstrsposs QU_CONNECTINGsflagssFuncLists FLWaitLevs FLSentLevsconnect_success(sselfsldbse((s@/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empQueue.pysConnectSs*   "     cCs|ii|dS(sNote an error.N(sselfscallbacks login_errorsmsg(sselfsmsg((s@/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empQueue.pysErroroscCsEtitjodSn|iitiit`tt_dS(s%Break the connection with the server.N( sempQueuesflagss QU_DISCONNECTsselfscallbacksconnect_terminatessocketscloses QU_OFFLINE(sself((s@/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empQueue.pys Disconnectss  cCs|d }|d}titjo tt_n|tjotii|dSnt i d}|i djoP|tjo"|iid||fdSnd|_ tid|in|i djoQ|tjo"|iid||fdSnd|_ tid|d np|i djoQ|tjo"|iid||fdSnd |_ tid |d n|i d jop|tjo"|iid||fdSn|iiod |_ tidqd|_ tidn|i d joI|tjo"|iid||fdSnd|_ tidn6|i djo|tjo"|iid||fdSnd|_ tt_tit iio*tiidtddt i_ndt i_|io0tiidtdd|_ d|_ntiidtd|ii!t"|i#t|_$|i$i%n|i$i|dS(s+EmpIOQueue Handler: Process a line of data.iNsloginis[%s]%ssuser %siscoun %sscounispass %ssrepriskillisplayicsexec s first.emps start.emps connect.emp(&slinesprotosmsgsempQueuesflagss QU_CONNECTINGsQU_LOGINsC_ASYNCSs defParsersempDbsmegaDBsldbsselfspossC_INITscallbacks login_errorsSendNowsusernamesC_CMDOKs login_killsC_EXITs QU_FULLSYNCsdoFlagssDBIOs newDatabasesviewersioqsSends pathPrefixsneedSavessrcStarts firstConnects login_successs NormalHandlerscommandsoutsstart(sselfslinesldbsprotosmsg((s@/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empQueue.pysline}s|                           cCstidS(N(sviewersProcess(sself((s@/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empQueue.pyslullscCsYtitjo|in8titjod|_|itnt i ddS(sTry to connect to the server again. Calling this function is the natural conclusion of a call to the login_error() method described above. isUnknown internal error.N( sempQueuesflagss QU_DISCONNECTsselfsConnects QU_CONNECTINGsposslinesC_INITsviewersError(sself((s@/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empQueue.pysretrys ( s__name__s __module__s__doc__s__init__sConnectsErrors Disconnectslineslullsretry(((s@/mnt/gmirror/ports/games/ptkei/work/ptkei-1.18.1/src/empQueue.pys LoginHandler:s     L s AsyncHandlercBs tZdZdZdZRS(sHandle asyncrounous server data. Data received that is not associated with a command is processed by this class. The class requires the global viewer class to support the following methods: flash(), and inform() cCs|d tjoti|dn|d tjo)tid|dftiino|d t jo#|dt i dd