NETDLG.CPP.BAK 201 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295
  1. /*
  2. ** Command & Conquer(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /* $Header: F:\projects\c&c\vcs\code\netdlg.cpv 2.17 16 Oct 1995 16:52:26 JOE_BOSTIC $ */
  19. /***********************************************************************************************
  20. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  21. ***********************************************************************************************
  22. * *
  23. * Project Name : Command & Conquer *
  24. * *
  25. * File Name : NETDLG.CPP *
  26. * *
  27. * Programmer : Bill Randolph *
  28. * *
  29. * Start Date : January 23, 1995 *
  30. * *
  31. * Last Update : July 8, 1995 [BRR] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * *
  35. * These routines establish & maintain peer-to-peer connections between this system *
  36. * and all others in the game. Each system finds out the IPX address of the others, *
  37. * and forms a direct connection (IPXConnectionClass) to that system. Systems are *
  38. * found out via broadcast queries. Every system broadcasts its queries, and every *
  39. * system replies to queries it receives. At the point when the game owner signals *
  40. * 'OK', every system must know about all the other systems in the game. *
  41. * *
  42. * How Bridges are handled: *
  43. * Currently, bridges are handled by specifying the destination IPX address of the *
  44. * "server" (game owner's system) on the command-line. This address is used to *
  45. * derive a broadcast address to that destination network, and this system's queries *
  46. * are broadcast over its network & the server's network; replies to the queries come *
  47. * with each system's IPX address attached, so once we have the address, we can form *
  48. * a connection with any system on the bridged net. *
  49. * *
  50. * The flaw in this plan is that we can only cross one bridge. If there are 3 nets *
  51. * bridged (A, B, & C), and the server is on net B, and we're on net A, our broadcasts *
  52. * will reach nets A & B, but not C. The way to circumvent this (if it becomes a problem) *
  53. * would be to have the server tell us what other systems are in its game, not each *
  54. * individual player's system. Thus, each system would find out about all the other systems *
  55. * by interacting with the game's owner system (this would be more involved than what *
  56. * I'm doing here). *
  57. * *
  58. * Here's a list of all the different packets sent over the Global Channel: *
  59. * *
  60. * NET_QUERY_GAME *
  61. * (no other data) *
  62. * NET_ANSWER_GAME *
  63. * Name: game owner's name *
  64. * GameInfo: game's version & open state *
  65. * NET_QUERY_PLAYER *
  66. * Name: name of game we want players to respond for *
  67. * NET_ANSWER_PLAYER *
  68. * Name: player's name *
  69. * PlayerInfo: info about player *
  70. * NET_QUERY_JOIN *
  71. * Name: name of player wanting to join *
  72. * PlayerInfo: player's requested house & color *
  73. * NET_CONFIRM_JOIN *
  74. * PlayerInfo: approves player's house & color *
  75. * NET_REJECT_JOIN *
  76. * (no other data) *
  77. * NET_GAME_OPTIONS *
  78. * ScenarioInfo: info about scenario *
  79. * NET_SIGN_OFF *
  80. * Name: name of player signing off *
  81. * NET_PING *
  82. * (no other data) *
  83. * NET_GO *
  84. * Delay: value of one-way response time, in frames *
  85. * *
  86. *---------------------------------------------------------------------------------------------*
  87. * Functions: *
  88. * Clear_Game_List -- Clears the game-name listbox & 'Games' Vector *
  89. * Clear_Player_List -- Clears the player-name listbox & Vector *
  90. * Destroy_Connection -- destroys the given connection *
  91. * Get_Join_Responses -- sends queries for the Join Dialog *
  92. * Get_NewGame_Responses -- processes packets for New Game dialog *
  93. * Init_Network -- initializes network stuff *
  94. * Net_Join_Dialog -- lets user join an existing game, or start a new one *
  95. * Net_New_Dialog -- lets user start a new game *
  96. * Process_Global_Packet -- responds to remote queries *
  97. * Remote_Connect -- handles connecting this user to others *
  98. * Request_To_Join -- Sends a JOIN request packet to game owner *
  99. * Send_Join_Queries -- sends queries for the Join Dialog *
  100. * Shutdown_Network -- shuts down network stuff *
  101. * Compute_Name_CRC -- computes CRC from char string *
  102. * Net_Reconnect_Dialog -- Draws/updates the network reconnect dialog *
  103. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  104. #include "function.h"
  105. #include <time.h>
  106. #include "tcpip.h"
  107. #define SHOW_MONO 0
  108. #ifndef DEMO
  109. /*---------------------------------------------------------------------------
  110. The possible states of the join-game dialog
  111. ---------------------------------------------------------------------------*/
  112. typedef enum {
  113. JOIN_REJECTED = -1, // we've been rejected
  114. JOIN_NOTHING, // we're not trying to join a game
  115. JOIN_WAIT_CONFIRM, // we're asking to join, & waiting for confirmation
  116. JOIN_CONFIRMED, // we've been confirmed
  117. JOIN_GAME_START, // the game we've joined is starting
  118. } JoinStateType;
  119. /*---------------------------------------------------------------------------
  120. The possible return codes from Get_Join_Responses()
  121. ---------------------------------------------------------------------------*/
  122. typedef enum {
  123. EV_NONE, // nothing happened
  124. EV_STATE_CHANGE, // Join dialog is in a new state
  125. EV_NEW_GAME, // a new game was detected
  126. EV_NEW_PLAYER, // a new player was detected
  127. EV_PLAYER_SIGNOFF, // a player has signed off
  128. EV_GAME_SIGNOFF, // a gamed owner has signed off
  129. EV_GAME_OPTIONS, // a game options packet was received
  130. EV_MESSAGE, // a message was received
  131. } JoinEventType;
  132. /*
  133. ******************************** Prototypes *********************************
  134. */
  135. static int Net_Join_Dialog(void);
  136. static void Clear_Game_List (ListClass *gamelist);
  137. static void Clear_Player_List (ListClass *playerlist);
  138. static int Request_To_Join (char *playername, int join_index, ListClass *playerlist,
  139. HousesType house, int color);
  140. static void Send_Join_Queries(int curgame, int gamenow, int playernow);
  141. static JoinEventType Get_Join_Responses(JoinStateType *joinstate, ListClass *gamelist,
  142. ColorListClass *playerlist, int join_index);
  143. static int Net_New_Dialog(void);
  144. static JoinEventType Get_NewGame_Responses(ColorListClass *playerlist);
  145. static int Net_Fake_New_Dialog(void);
  146. static int Net_Fake_Join_Dialog(void);
  147. /***********************************************************************************************
  148. * Init_Network -- initializes network stuff *
  149. * *
  150. * INPUT: *
  151. * none. *
  152. * *
  153. * OUTPUT: *
  154. * true = Initialization OK, false = error *
  155. * *
  156. * WARNINGS: *
  157. * none. *
  158. * *
  159. * HISTORY: *
  160. * 02/14/1995 BR : Created. *
  161. *=============================================================================================*/
  162. bool Init_Network (void)
  163. {
  164. NetNumType net;
  165. NetNodeType node;
  166. /*------------------------------------------------------------------------
  167. This call allocates all necessary queue buffers, allocates Real-mode
  168. memory, and commands IPX to start listening on the Global Channel.
  169. ------------------------------------------------------------------------*/
  170. if (!Ipx.Init())
  171. return(false);
  172. /*------------------------------------------------------------------------
  173. Allocate our "meta-packet" buffer
  174. ------------------------------------------------------------------------*/
  175. if (!MetaPacket) {
  176. MetaPacket = new char [sizeof (EventClass) * MAX_EVENTS];
  177. }
  178. /*------------------------------------------------------------------------
  179. Set up the IPX manager to cross a bridge
  180. ------------------------------------------------------------------------*/
  181. if (!(GameToPlay == GAME_INTERNET)){
  182. if (IsBridge) {
  183. BridgeNet.Get_Address(net,node);
  184. Ipx.Set_Bridge(net);
  185. }
  186. }
  187. return(true);
  188. } /* end of Init_Network */
  189. /***********************************************************************************************
  190. * Shutdown_Network -- shuts down network stuff *
  191. * *
  192. * INPUT: *
  193. * none. *
  194. * *
  195. * OUTPUT: *
  196. * none. *
  197. * *
  198. * WARNINGS: *
  199. * none. *
  200. * *
  201. * HISTORY: *
  202. * 02/14/1995 BR : Created. *
  203. *=============================================================================================*/
  204. void Shutdown_Network (void)
  205. {
  206. /*------------------------------------------------------------------------
  207. Broadcast a sign-off packet, by sending the packet over the Global Channel,
  208. telling the IPX Manager that no ACK is required, and specifying a NULL
  209. destination address.
  210. ------------------------------------------------------------------------*/
  211. memset (&GPacket, 0, sizeof(GlobalPacketType));
  212. GPacket.Command = NET_SIGN_OFF;
  213. strcpy (GPacket.Name, MPlayerName);
  214. Ipx.Send_Global_Message (&GPacket, sizeof (GlobalPacketType), 0, NULL);
  215. Ipx.Send_Global_Message (&GPacket, sizeof (GlobalPacketType), 0, NULL);
  216. if (IsBridge && !Winsock.Get_Connected()) {
  217. Ipx.Send_Global_Message (&GPacket, sizeof(GlobalPacketType), 0, &BridgeNet);
  218. Ipx.Send_Global_Message (&GPacket, sizeof(GlobalPacketType), 0, &BridgeNet);
  219. }
  220. /*------------------------------------------------------------------------
  221. Wait for the packets to finish going out (or the Global Channel times out)
  222. ------------------------------------------------------------------------*/
  223. for (;;) {
  224. if (Ipx.Global_Num_Send()==0) {
  225. break;
  226. }
  227. Ipx.Service();
  228. }
  229. /*------------------------------------------------------------------------
  230. Delete our "meta-packet"
  231. ------------------------------------------------------------------------*/
  232. delete [] MetaPacket;
  233. MetaPacket = 0;
  234. /*------------------------------------------------------------------------
  235. If I was in a game, I'm not now, so clear the game name
  236. ------------------------------------------------------------------------*/
  237. MPlayerGameName[0] = 0;
  238. }
  239. /***********************************************************************************************
  240. * Process_Global_Packet -- responds to remote queries *
  241. * *
  242. * The only commands from other systems this routine responds to are NET_QUERY_GAME *
  243. * and NET_QUERY_PLAYER. The other commands are too context-specific to be able *
  244. * to handle here, such as joining the game or signing off; but this routine handles *
  245. * the majority of the program's needs. *
  246. * *
  247. * INPUT: *
  248. * packet ptr to packet to process *
  249. * address source address of sender *
  250. * *
  251. * OUTPUT: *
  252. * true = packet was processed, false = wasn't *
  253. * *
  254. * WARNINGS: *
  255. * MPlayerName & MPlayerGameName must have been filled in before this function *
  256. * can be called. *
  257. * *
  258. * HISTORY: *
  259. * 02/15/1995 BR : Created. *
  260. *=============================================================================================*/
  261. bool Process_Global_Packet(GlobalPacketType *packet, IPXAddressClass *address)
  262. {
  263. GlobalPacketType mypacket;
  264. /*
  265. ---------------- Another system asking what game this is -----------------
  266. */
  267. if (packet->Command==NET_QUERY_GAME && NetStealth==0) {
  268. /*.....................................................................
  269. If the game is closed, let every player respond, and let the sender of
  270. the query sort it all out. This way, if the game's host exits the game,
  271. the game still shows up on other players' dialogs.
  272. If the game is open, only the game owner may respond.
  273. .....................................................................*/
  274. if (strlen(MPlayerName) > 0 && strlen(MPlayerGameName) > 0 &&
  275. ((!NetOpen) || (NetOpen && !strcmp(MPlayerName,MPlayerGameName)))) {
  276. memset (packet, 0, sizeof(GlobalPacketType));
  277. mypacket.Command = NET_ANSWER_GAME;
  278. strcpy(mypacket.Name, MPlayerGameName);
  279. #ifdef PATCH
  280. if (IsV107) {
  281. mypacket.GameInfo.Version = 1;
  282. } else {
  283. mypacket.GameInfo.Version = 2;
  284. }
  285. #else
  286. mypacket.GameInfo.Version = Version_Number();
  287. #endif
  288. mypacket.GameInfo.IsOpen = NetOpen;
  289. Ipx.Send_Global_Message (&mypacket, sizeof(GlobalPacketType), 1,
  290. address);
  291. }
  292. return(true);
  293. } else {
  294. /*
  295. ----------------- Another system asking what player I am -----------------
  296. */
  297. if (packet->Command==NET_QUERY_PLAYER &&
  298. !strcmp (packet->Name, MPlayerGameName) &&
  299. (strlen(MPlayerGameName) > 0) && NetStealth==0) {
  300. memset (packet, 0, sizeof(GlobalPacketType));
  301. mypacket.Command = NET_ANSWER_PLAYER;
  302. strcpy(mypacket.Name, MPlayerName);
  303. mypacket.PlayerInfo.House = MPlayerHouse;
  304. mypacket.PlayerInfo.Color = MPlayerColorIdx;
  305. mypacket.PlayerInfo.NameCRC = Compute_Name_CRC(MPlayerGameName);
  306. Ipx.Send_Global_Message (&mypacket, sizeof(GlobalPacketType), 1, address);
  307. return(true);
  308. }
  309. }
  310. return(false);
  311. }
  312. /***********************************************************************************************
  313. * Destroy_Connection -- destroys the given connection *
  314. * *
  315. * Call this routine when a connection goes bad, or another player signs off. *
  316. * *
  317. * INPUT: *
  318. * id connection ID to destroy *
  319. * error 0 = user signed off; 1 = connection error; otherwise, no error is shown. *
  320. * *
  321. * OUTPUT: *
  322. * none. *
  323. * *
  324. * WARNINGS: *
  325. * none. *
  326. * *
  327. * HISTORY: *
  328. * 04/22/1995 BR : Created. *
  329. *=============================================================================================*/
  330. void Destroy_Connection(int id, int error)
  331. {
  332. int i,j;
  333. HousesType house;
  334. HouseClass *housep;
  335. char txt[80];
  336. /*------------------------------------------------------------------------
  337. Create a message to display to the user
  338. ------------------------------------------------------------------------*/
  339. txt[0] = '\0';
  340. if (error==1) {
  341. sprintf(txt,Text_String(TXT_CONNECTION_LOST),Ipx.Connection_Name(id));
  342. } else if (error==0) {
  343. sprintf(txt,Text_String(TXT_LEFT_GAME),Ipx.Connection_Name(id));
  344. }
  345. if (strlen(txt)) {
  346. Messages.Add_Message (txt,
  347. MPlayerTColors[MPlayerID_To_ColorIndex((unsigned char)id)],
  348. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_FULLSHADOW, 600, 0, 0);
  349. Map.Flag_To_Redraw(false);
  350. }
  351. /*------------------------------------------------------------------------
  352. Delete the IPX connection, shift the MPlayerID's & MPlayerHouses' back one.
  353. ------------------------------------------------------------------------*/
  354. Ipx.Delete_Connection(id);
  355. for (i = 0; i < MPlayerCount; i++) {
  356. if (MPlayerID[i] == (unsigned char)id) {
  357. /*..................................................................
  358. Turn the player's house over to the computer's AI
  359. ..................................................................*/
  360. house = MPlayerHouses[i];
  361. housep = HouseClass::As_Pointer (house);
  362. housep->IsHuman = false;
  363. housep->IsStarted = true;
  364. /*..................................................................
  365. Move arrays back by one
  366. ..................................................................*/
  367. for (j = i; j < MPlayerCount - 1; j++) {
  368. MPlayerID[j] = MPlayerID[j + 1];
  369. MPlayerHouses[j] = MPlayerHouses[j + 1];
  370. strcpy (MPlayerNames[j], MPlayerNames[j+1]);
  371. TheirProcessTime[j] = TheirProcessTime[j+1];
  372. }
  373. }
  374. }
  375. MPlayerCount--;
  376. /*------------------------------------------------------------------------
  377. If we're the last player left, tell the user.
  378. ------------------------------------------------------------------------*/
  379. if (MPlayerCount == 1) {
  380. sprintf(txt,"%s",Text_String(TXT_JUST_YOU_AND_ME));
  381. Messages.Add_Message (txt,
  382. MPlayerTColors[MPlayerID_To_ColorIndex((unsigned char)id)],
  383. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_FULLSHADOW, 600, 0, 0);
  384. Map.Flag_To_Redraw(false);
  385. }
  386. } /* end of Destroy_Connection */
  387. /***********************************************************************************************
  388. * Remote_Connect -- handles connecting this user to others *
  389. * *
  390. * INPUT: *
  391. * none. *
  392. * *
  393. * OUTPUT: *
  394. * true = connections established; false = not *
  395. * *
  396. * WARNINGS: *
  397. * none. *
  398. * *
  399. * HISTORY: *
  400. * 02/14/1995 BR : Created. *
  401. *=============================================================================================*/
  402. bool Remote_Connect(void)
  403. {
  404. int rc;
  405. int stealth; // original state of NetStealth flag
  406. /*------------------------------------------------------------------------
  407. Init network timing parameters; these values should work for both a "real"
  408. network, and a simulated modem network (ie Kali)
  409. ------------------------------------------------------------------------*/
  410. Ipx.Set_Timing ( 30, // retry 2 times per second
  411. -1, // ignore max retries
  412. 600); // give up after 10 seconds
  413. /*------------------------------------------------------------------------
  414. Save the original value of the NetStealth flag, so we can turn stealth
  415. off for now (during this portion of the dialogs, we must show ourselves)
  416. ------------------------------------------------------------------------*/
  417. stealth = NetStealth;
  418. NetStealth = 0;
  419. /*------------------------------------------------------------------------
  420. Init my game name to 0-length, since I haven't joined any game yet.
  421. ------------------------------------------------------------------------*/
  422. MPlayerGameName[0] = 0;
  423. /*------------------------------------------------------------------------
  424. The game is now "open" for joining. Close it as soon as we exit this
  425. routine.
  426. ------------------------------------------------------------------------*/
  427. NetOpen = 1;
  428. /*------------------------------------------------------------------------
  429. Read the default values from the INI file
  430. ------------------------------------------------------------------------*/
  431. Read_MultiPlayer_Settings ();
  432. /*------------------------------------------------------------------------
  433. Keep looping until something useful happens.
  434. ------------------------------------------------------------------------*/
  435. while (1) {
  436. /*---------------------------------------------------------------------
  437. Pop up the network Join/New dialog
  438. ---------------------------------------------------------------------*/
  439. rc = Net_Join_Dialog();
  440. /*---------------------------------------------------------------------
  441. -1 = user selected Cancel
  442. ---------------------------------------------------------------------*/
  443. if (rc==-1) {
  444. NetStealth = stealth;
  445. NetOpen = 0;
  446. return(false);
  447. } else {
  448. /*---------------------------------------------------------------------
  449. 0 = user has joined an existing game; save values & return
  450. ---------------------------------------------------------------------*/
  451. if (rc==0) {
  452. Write_MultiPlayer_Settings ();
  453. NetStealth = stealth;
  454. NetOpen = 0;
  455. return(true);
  456. } else {
  457. /*---------------------------------------------------------------------
  458. 1 = user requests New Network Game
  459. ---------------------------------------------------------------------*/
  460. if (rc==1) {
  461. /*..................................................................
  462. Pop up the New Network Game dialog; if user selects OK, return
  463. 'true'; otherwise, return to the Join Dialog.
  464. ..................................................................*/
  465. if (Net_New_Dialog()) {
  466. Write_MultiPlayer_Settings ();
  467. NetOpen = 0;
  468. NetStealth = stealth;
  469. NetOpen = 0;
  470. return(true);
  471. } else {
  472. continue;
  473. }
  474. }
  475. }
  476. }
  477. }
  478. }
  479. /***********************************************************************************************
  480. * Remote_Connect -- handles connecting this host to the server in an internet game *
  481. * *
  482. * INPUT: *
  483. * none. *
  484. * *
  485. * OUTPUT: *
  486. * true = connections established; false = not *
  487. * *
  488. * WARNINGS: *
  489. * none. *
  490. * *
  491. * HISTORY: *
  492. * 02/14/1995 BR : Created. *
  493. *=============================================================================================*/
  494. bool Server_Remote_Connect(void)
  495. {
  496. int stealth; // original state of NetStealth flag
  497. /*------------------------------------------------------------------------
  498. Init network timing parameters; these values should work for both a "real"
  499. network, and a simulated modem network (ie Kali)
  500. ------------------------------------------------------------------------*/
  501. Ipx.Set_Timing ( 30, // retry 2 times per second
  502. -1, // ignore max retries
  503. 600); // give up after 10 seconds
  504. /*------------------------------------------------------------------------
  505. Save the original value of the NetStealth flag, so we can turn stealth
  506. off for now (during this portion of the dialogs, we must show ourselves)
  507. ------------------------------------------------------------------------*/
  508. stealth = NetStealth;
  509. NetStealth = 0;
  510. /*------------------------------------------------------------------------
  511. The game is now "open" for joining. Close it as soon as we exit this
  512. routine.
  513. ------------------------------------------------------------------------*/
  514. NetOpen = 1;
  515. /*------------------------------------------------------------------------
  516. Read the default values from the INI file
  517. ------------------------------------------------------------------------*/
  518. Read_MultiPlayer_Settings ();
  519. if (!Net_Fake_New_Dialog()){
  520. Write_MultiPlayer_Settings ();
  521. return (false);
  522. }
  523. NetOpen = 0;
  524. NetStealth = stealth;
  525. Write_MultiPlayer_Settings ();
  526. return (true);
  527. }
  528. /***********************************************************************************************
  529. * Client_Remote_Connect -- handles connecting this client to the server in an internet game *
  530. * *
  531. * INPUT: *
  532. * none. *
  533. * *
  534. * OUTPUT: *
  535. * true = connections established; false = not *
  536. * *
  537. * WARNINGS: *
  538. * none. *
  539. * *
  540. * HISTORY: *
  541. * 02/14/1995 ST : Created. *
  542. *=============================================================================================*/
  543. bool Client_Remote_Connect(void)
  544. {
  545. int rc;
  546. int stealth; // original state of NetStealth flag
  547. /*------------------------------------------------------------------------
  548. Init network timing parameters; these values should work for both a "real"
  549. network, and a simulated modem network (ie Kali)
  550. ------------------------------------------------------------------------*/
  551. Ipx.Set_Timing ( 30, // retry 2 times per second
  552. -1, // ignore max retries
  553. 600); // give up after 10 seconds
  554. /*------------------------------------------------------------------------
  555. Save the original value of the NetStealth flag, so we can turn stealth
  556. off for now (during this portion of the dialogs, we must show ourselves)
  557. ------------------------------------------------------------------------*/
  558. stealth = NetStealth;
  559. NetStealth = 0;
  560. /*------------------------------------------------------------------------
  561. The game is now "open" for joining. Close it as soon as we exit this
  562. routine.
  563. ------------------------------------------------------------------------*/
  564. NetOpen = 1;
  565. /*------------------------------------------------------------------------
  566. Read the default values from the INI file
  567. ------------------------------------------------------------------------*/
  568. Read_MultiPlayer_Settings ();
  569. /*---------------------------------------------------------------------
  570. Pop up the network Join/New dialog
  571. ---------------------------------------------------------------------*/
  572. rc = Net_Fake_Join_Dialog();
  573. Write_MultiPlayer_Settings ();
  574. NetStealth = stealth;
  575. NetOpen = 0;
  576. if (rc == -1) {
  577. return(false);
  578. } else {
  579. return(true);
  580. }
  581. }
  582. /***********************************************************************************************
  583. * Net_Join_Dialog -- lets user join an existing game or start a new one *
  584. * *
  585. * This dialog displays an edit field for the player's name, and a list of all non-stealth- *
  586. * mode games. Clicking once on a game name displays a list of who's in that game. Clicking *
  587. * "New" takes the user to the Net_New dialog, where he waits for other users to join his *
  588. * game. All other input is done through this dialog. *
  589. * *
  590. * The dialog has several "states": *
  591. * *
  592. * 1) Initially, it waits for the user to fill in his/her name and then to select Join or New; *
  593. * if New is selected, this dialog is exited. *
  594. * *
  595. * 2) If Join is selected, the Join & New buttons are removed, but the Cancel button remains. *
  596. * The join request is transmitted to the game's owner, and the message "Waiting for *
  597. * Confirmation" is displayed, until a confirmation or denial is received from the game's *
  598. * owner. The user may click Cancel at this point to cancel the join request. *
  599. * (Once Join is selected, the name editing field is disabled, and becomes a display-only *
  600. * field. If cancel is selected, it reappears as an edit field.) The user can still click *
  601. * around & see who's in which games. *
  602. * *
  603. * 3) If the join request is denied, the dialog re-initializes to its pre-join state; the *
  604. * Join & New buttons reappear, & the Name field is available again. *
  605. * *
  606. * 4) If join confirmation is obtained, the message just changes to "Confirmed. Waiting for *
  607. * Entry Signal." or some such nonsense. The user can still click around & see who's *
  608. * in which games. *
  609. * *
  610. * Any game running in Stealth mode won't show up on this dialog. *
  611. * *
  612. * ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ *
  613. * ³ Network Games ³ *
  614. * ³ ³ *
  615. * ³ Your Name: ____________ ³ *
  616. * ³ House: [GDI] [NOD] ³ *
  617. * ³ Desired Color: [ ][ ][ ][ ] ³ *
  618. * ³ ³ *
  619. * ³ Games Players ³ *
  620. * ³ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄ¿ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄ¿ ³ *
  621. * ³ ³(Bill's Game )³³ ³ Peter Parker GDI ³³ ³ *
  622. * ³ ³ Peter Parker's Game ÃÄ´ ³ Mary Jane GDI ÃÄ´ ³ *
  623. * ³ ³(Magnum PI's Game )³ ³ ³ JJ Jameson NOD ³ ³ ³ *
  624. * ³ ³ ÃÄ´ ³ ÃÄ´ ³ *
  625. * ³ ³ ³³ ³ ³³ ³ *
  626. * ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÙ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÙ ³ *
  627. * ³ Scenario: Big Long Description ³ *
  628. * ³ Starting Credits: xxxx ³ *
  629. * ³ Count: --- Level: --- ³ *
  630. * ³ Bases: ON Crates: ON ³ *
  631. * ³ Tiberium: ON AI Players: ON ³ *
  632. * ³ ³ *
  633. * ³ [Join] [Cancel] [New] ³ *
  634. * ³ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ *
  635. * ³ ³ ³ ³ *
  636. * ³ ³ ³ ³ *
  637. * ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ³ *
  638. * ³ [Send Message] ³ *
  639. * ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ *
  640. * *
  641. * INPUT: *
  642. * none. *
  643. * *
  644. * OUTPUT: *
  645. * -1 = cancel, 0 = OK, 1 = New net game requested *
  646. * *
  647. * WARNINGS: *
  648. * none. *
  649. * *
  650. * HISTORY: *
  651. * 02/14/1995 BR : Created. *
  652. *=============================================================================================*/
  653. static int Net_Join_Dialog(void)
  654. {
  655. int factor = (SeenBuff.Get_Width() == 320) ? 1 : 2;
  656. /*........................................................................
  657. Dialog & button dimensions
  658. ........................................................................*/
  659. /* ###Change collision detected! C:\PROJECTS\CODE\NETDLG.CPP... */
  660. int d_dialog_w = 287 *factor; // dialog width
  661. int d_dialog_h = 198*factor; // dialog height
  662. int d_dialog_x = ((320*factor - d_dialog_w) / 2); // dialog x-coord
  663. int d_dialog_y = ((200*factor - d_dialog_h) / 2); // centered y-coord
  664. int d_dialog_cx = d_dialog_x + (d_dialog_w / 2); // center x-coord
  665. int d_txt6_h = 6*factor+1; // ht of 6-pt text
  666. int d_margin1 = 5*factor; // large margin
  667. int d_margin2 = 2*factor; // small margin
  668. int d_name_w = 70*factor;
  669. int d_name_h = 9*factor;
  670. int d_name_x = d_dialog_cx - 10*factor;
  671. int d_name_y = d_dialog_y + d_margin1 + d_txt6_h + d_txt6_h;
  672. int d_gdi_w = 30*factor;
  673. int d_gdi_h = 9*factor;
  674. int d_gdi_x = d_dialog_cx - 10*factor;
  675. int d_gdi_y = d_name_y + d_name_h + d_margin2;
  676. int d_nod_w = 30*factor;
  677. int d_nod_h = 9*factor;
  678. int d_nod_x = d_gdi_x + d_gdi_w;
  679. int d_nod_y = d_name_y + d_name_h + d_margin2;
  680. int d_color_w = 10*factor;
  681. int d_color_h = 9*factor;
  682. int d_color_y = d_nod_y + d_nod_h + d_margin2;
  683. int d_gamelist_w = 160*factor;
  684. int d_gamelist_h = 27*factor;
  685. int d_gamelist_x = d_dialog_x + d_margin1;
  686. int d_gamelist_y = d_color_y + d_color_h + d_margin1 + d_txt6_h;
  687. int d_playerlist_w = 106*factor;
  688. int d_playerlist_h = 27*factor;
  689. int d_playerlist_x = d_dialog_x + d_dialog_w - d_margin1 - d_playerlist_w;
  690. int d_playerlist_y = d_color_y + d_color_h + d_margin1 + d_txt6_h;
  691. int d_msg1_y = d_gamelist_y + d_gamelist_h + d_margin1;
  692. int d_msg2_y = d_msg1_y + d_txt6_h;
  693. int d_msg3_y = d_msg2_y + d_txt6_h;
  694. int d_msg4_y = d_msg3_y + d_txt6_h;
  695. int d_msg5_y = d_msg4_y + d_txt6_h;
  696. int d_join_w = 40*factor;
  697. int d_join_h = 9*factor;
  698. int d_join_x = d_dialog_x + (d_dialog_w / 6) - (d_join_w / 2);
  699. int d_join_y = d_msg5_y + d_txt6_h + d_margin1;
  700. #if (GERMAN | FRENCH)
  701. int d_cancel_w = 50*factor;
  702. #else
  703. int d_cancel_w = 40*factor;
  704. #endif
  705. int d_cancel_h = 9*factor;
  706. int d_cancel_x = d_dialog_cx - d_cancel_w / 2;
  707. int d_cancel_y = d_msg5_y + d_txt6_h + d_margin1;
  708. int d_new_w = 40*factor;
  709. int d_new_h = 9*factor;
  710. int d_new_x = d_dialog_x + ((d_dialog_w * 5) / 6) - (d_new_w / 2);
  711. int d_new_y = d_msg5_y + d_txt6_h + d_margin1;
  712. int d_message_w = d_dialog_w - (d_margin1 * 2);
  713. int d_message_h = 34*factor;
  714. int d_message_x = d_dialog_x + d_margin1;
  715. int d_message_y = d_cancel_y + d_cancel_h + d_margin1;
  716. int d_send_w = 80*factor;
  717. int d_send_h = 9*factor;
  718. int d_send_x = d_dialog_cx - (d_send_w / 2);
  719. int d_send_y = d_message_y + d_message_h + d_margin2;
  720. /*........................................................................
  721. Button Enumerations
  722. ........................................................................*/
  723. enum {
  724. BUTTON_NAME = 100,
  725. BUTTON_GDI,
  726. BUTTON_NOD,
  727. BUTTON_GAMELIST,
  728. BUTTON_PLAYERLIST,
  729. BUTTON_JOIN,
  730. BUTTON_CANCEL,
  731. BUTTON_NEW,
  732. BUTTON_SEND,
  733. };
  734. /*........................................................................
  735. Redraw values: in order from "top" to "bottom" layer of the dialog
  736. ........................................................................*/
  737. typedef enum {
  738. REDRAW_NONE = 0,
  739. REDRAW_MESSAGE,
  740. REDRAW_COLORS,
  741. REDRAW_BUTTONS,
  742. REDRAW_BACKGROUND,
  743. REDRAW_ALL = REDRAW_BACKGROUND
  744. } RedrawType;
  745. /*........................................................................
  746. Dialog variables
  747. ........................................................................*/
  748. RedrawType display = REDRAW_ALL; // redraw level
  749. bool process = true; // process while true
  750. KeyNumType input;
  751. int cbox_x[] = { d_gdi_x,
  752. d_gdi_x + d_color_w,
  753. d_gdi_x + (d_color_w * 2),
  754. d_gdi_x + (d_color_w * 3),
  755. d_gdi_x + (d_color_w * 4),
  756. d_gdi_x + (d_color_w * 5)};
  757. JoinStateType joinstate = JOIN_NOTHING; // current "state" of this dialog
  758. char namebuf[MPLAYER_NAME_MAX] = {0}; // buffer for player's name
  759. int tabs[] = {77*factor}; // tabs for player list box
  760. int game_index = -1; // index of currently-selected game
  761. int join_index = -1; // index of game we're joining
  762. int rc = 0; // -1 = user cancelled, 1 = New
  763. JoinEventType event; // event from incoming packet
  764. int i,j; // loop counter
  765. char txt[80];
  766. char const *p;
  767. int parms_received; // 1 = game options received
  768. int found;
  769. unsigned char tmp_id[MAX_PLAYERS]; // temp storage for sorting player ID's
  770. int min_index; // for sorting player ID's
  771. unsigned char min_id; // for sorting player ID's
  772. unsigned char id; // connection ID
  773. char * item;
  774. unsigned long starttime;
  775. NodeNameType *who;
  776. int message_length;
  777. int sent_so_far;
  778. unsigned short magic_number;
  779. unsigned short crc;
  780. void const *up_button;
  781. void const *down_button;
  782. if (InMainLoop){
  783. up_button = Hires_Retrieve("BTN-UP.SHP");
  784. down_button = Hires_Retrieve("BTN-DN.SHP");
  785. }else{
  786. up_button = Hires_Retrieve("BTN-UP2.SHP");
  787. down_button = Hires_Retrieve("BTN-DN2.SHP");
  788. }
  789. /*........................................................................
  790. Buttons
  791. ........................................................................*/
  792. GadgetClass *commands; // button list
  793. EditClass name_edt (BUTTON_NAME,
  794. namebuf, MPLAYER_NAME_MAX, TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  795. d_name_x, d_name_y, d_name_w, d_name_h, EditClass::ALPHANUMERIC);
  796. TextButtonClass gdibtn(BUTTON_GDI, TXT_G_D_I,
  797. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  798. d_gdi_x, d_gdi_y, d_gdi_w, d_gdi_h);
  799. TextButtonClass nodbtn(BUTTON_NOD, TXT_N_O_D,
  800. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  801. d_nod_x, d_nod_y, d_nod_w, d_nod_h);
  802. ListClass gamelist(BUTTON_GAMELIST,
  803. d_gamelist_x, d_gamelist_y, d_gamelist_w, d_gamelist_h,
  804. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  805. up_button,
  806. down_button);
  807. ColorListClass playerlist(BUTTON_PLAYERLIST,
  808. d_playerlist_x, d_playerlist_y, d_playerlist_w, d_playerlist_h,
  809. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  810. up_button,
  811. down_button);
  812. TextButtonClass joinbtn(BUTTON_JOIN, TXT_JOIN,
  813. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  814. #ifdef FRENCH
  815. d_join_x, d_join_y);
  816. #else
  817. d_join_x, d_join_y, d_join_w, d_join_h);
  818. #endif
  819. TextButtonClass cancelbtn(BUTTON_CANCEL, TXT_CANCEL,
  820. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  821. #if (GERMAN | FRENCH)
  822. d_cancel_x, d_cancel_y);
  823. #else
  824. d_cancel_x, d_cancel_y, d_cancel_w, d_cancel_h);
  825. #endif
  826. TextButtonClass newbtn(BUTTON_NEW, TXT_NEW,
  827. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  828. d_new_x, d_new_y, d_new_w, d_new_h);
  829. TextButtonClass sendbtn(BUTTON_SEND, TXT_SEND_MESSAGE,
  830. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  831. #if (GERMAN | FRENCH)
  832. d_send_x, d_send_y);
  833. #else
  834. d_send_x, d_send_y, d_send_w, d_send_h);
  835. #endif
  836. playerlist.Set_Tabs(tabs);
  837. /*
  838. ----------------------------- Various Inits ------------------------------
  839. */
  840. MPlayerColorIdx = MPlayerPrefColor; // init my preferred color
  841. strcpy (namebuf, MPlayerName); // set my name
  842. name_edt.Set_Text(namebuf,MPLAYER_NAME_MAX);
  843. name_edt.Set_Color (MPlayerTColors[MPlayerColorIdx]);
  844. playerlist.Set_Selected_Style(ColorListClass::SELECT_NONE);
  845. if (MPlayerHouse==HOUSE_GOOD) {
  846. gdibtn.Turn_On();
  847. } else {
  848. nodbtn.Turn_On();
  849. }
  850. Fancy_Text_Print("", 0, 0, CC_GREEN, TBLACK,
  851. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW);
  852. Messages.Init (d_message_x + 2, d_message_y + 2, 4,
  853. MAX_MESSAGE_LENGTH, d_txt6_h);
  854. /*
  855. --------------------------- Send network query ---------------------------
  856. */
  857. Send_Join_Queries (game_index, 1, 0);
  858. Load_Title_Screen("HTITLE.PCX", &HidPage, Palette);
  859. HidPage.Blit(SeenBuff);
  860. Set_Palette(Palette);
  861. /*
  862. ---------------------------- Init Mono Output ----------------------------
  863. */
  864. #if(SHOW_MONO)
  865. Ipx.Configure_Debug(-1, sizeof (GlobalHeaderType),
  866. sizeof(NetCommandType), GlobalPacketNames, 11);
  867. Ipx.Mono_Debug_Print(-1,1);
  868. #endif
  869. while (Get_Mouse_State() > 0) Show_Mouse();
  870. /*
  871. ---------------------------- Processing loop -----------------------------
  872. */
  873. while (process) {
  874. /*
  875. ** If we have just received input focus again after running in the background then
  876. ** we need to redraw.
  877. */
  878. if (AllSurfaces.SurfacesRestored){
  879. AllSurfaces.SurfacesRestored=FALSE;
  880. display=REDRAW_ALL;
  881. }
  882. #if(SHOW_MONO)
  883. Ipx.Mono_Debug_Print(-1,0);
  884. #endif
  885. /*
  886. ...................... Refresh display if needed ......................
  887. */
  888. if (display) {
  889. Hide_Mouse();
  890. /*
  891. .................. Redraw backgound & dialog box ...................
  892. */
  893. if (display >= REDRAW_BACKGROUND) {
  894. Load_Title_Screen("HTITLE.PCX", &HidPage, Palette);
  895. HidPage.Blit(SeenBuff);
  896. Set_Palette(Palette);
  897. Dialog_Box(d_dialog_x, d_dialog_y, d_dialog_w, d_dialog_h);
  898. /*...............................................................
  899. Dialog & Field labels
  900. ...............................................................*/
  901. Draw_Caption (TXT_JOIN_NETWORK_GAME, d_dialog_x, d_dialog_y, d_dialog_w);
  902. Fancy_Text_Print(TXT_YOUR_NAME,
  903. d_name_x - 5, d_name_y + 1, CC_GREEN, TBLACK,
  904. TPF_RIGHT | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW);
  905. Fancy_Text_Print(TXT_SIDE_COLON,
  906. d_gdi_x - 5, d_gdi_y + 1, CC_GREEN, TBLACK,
  907. TPF_RIGHT | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW);
  908. Fancy_Text_Print(TXT_COLOR_COLON,
  909. cbox_x[0] - 5, d_color_y + 1, CC_GREEN, TBLACK,
  910. TPF_RIGHT | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW);
  911. Fancy_Text_Print(TXT_GAMES,
  912. d_gamelist_x + (d_gamelist_w / 2), d_gamelist_y - d_txt6_h,
  913. CC_GREEN, TBLACK,
  914. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW);
  915. Fancy_Text_Print(TXT_PLAYERS,
  916. d_playerlist_x + (d_playerlist_w / 2), d_playerlist_y - d_txt6_h,
  917. CC_GREEN, TBLACK,
  918. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW);
  919. /*...............................................................
  920. Join-state-specific labels:
  921. ...............................................................*/
  922. if (joinstate > JOIN_NOTHING) {
  923. Fancy_Text_Print(namebuf, d_name_x, d_name_y + 1, CC_GREEN,
  924. TBLACK, TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW);
  925. if (MPlayerHouse==HOUSE_GOOD) {
  926. Fancy_Text_Print(TXT_G_D_I, d_gdi_x, d_gdi_y + 1, CC_GREEN,
  927. TBLACK, TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW);
  928. } else {
  929. Fancy_Text_Print(TXT_N_O_D, d_gdi_x, d_gdi_y + 1, CC_GREEN,
  930. TBLACK, TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW);
  931. }
  932. }
  933. /*
  934. .................... Rebuild the button list ....................
  935. */
  936. cancelbtn.Zap();
  937. gamelist.Zap();
  938. playerlist.Zap();
  939. gdibtn.Zap();
  940. nodbtn.Zap();
  941. name_edt.Zap();
  942. joinbtn.Zap();
  943. newbtn.Zap();
  944. sendbtn.Zap();
  945. commands = &cancelbtn;
  946. gamelist.Add_Tail(*commands);
  947. playerlist.Add_Tail(*commands);
  948. /*...............................................................
  949. Only add the name edit field, the House, Join & New buttons if
  950. we're doing nothing, or we've just been rejected.
  951. ...............................................................*/
  952. if (joinstate <= JOIN_NOTHING) {
  953. gdibtn.Add_Tail(*commands);
  954. nodbtn.Add_Tail(*commands);
  955. name_edt.Add_Tail(*commands);
  956. joinbtn.Add_Tail(*commands);
  957. newbtn.Add_Tail(*commands);
  958. }
  959. if (joinstate == JOIN_CONFIRMED)
  960. sendbtn.Add_Tail(*commands);
  961. }
  962. /*
  963. .......................... Redraw buttons ..........................
  964. */
  965. if (display >= REDRAW_BUTTONS) {
  966. commands->Draw_All();
  967. }
  968. /*..................................................................
  969. Draw the color boxes
  970. ..................................................................*/
  971. if (display >= REDRAW_COLORS) {
  972. for (i = 0; i < MAX_MPLAYER_COLORS; i++) {
  973. LogicPage->Fill_Rect (cbox_x[i] + 1, d_color_y + 1,
  974. cbox_x[i] + 1 + d_color_w - 2, d_color_y + 1 + d_color_h - 2,
  975. MPlayerGColors[i]);
  976. if (i == MPlayerColorIdx) {
  977. Draw_Box(cbox_x[i], d_color_y, d_color_w, d_color_h,
  978. BOXSTYLE_GREEN_DOWN, false);
  979. } else {
  980. Draw_Box(cbox_x[i], d_color_y, d_color_w, d_color_h,
  981. BOXSTYLE_GREEN_RAISED, false);
  982. }
  983. }
  984. }
  985. /*..................................................................
  986. Draw the message:
  987. - Erase an old message first
  988. - If we're in a game, print the game options (if they've been
  989. received)
  990. - If we've been rejected from a game, print that message
  991. ..................................................................*/
  992. if (display >= REDRAW_MESSAGE) {
  993. Draw_Box(d_message_x, d_message_y, d_message_w, d_message_h,
  994. BOXSTYLE_GREEN_BORDER, true);
  995. Messages.Draw();
  996. LogicPage->Fill_Rect( d_dialog_x + 2,
  997. d_msg1_y,
  998. d_dialog_x + d_dialog_w - 4,
  999. d_msg5_y + d_txt6_h,
  1000. BLACK);
  1001. if (joinstate==JOIN_CONFIRMED && parms_received) {
  1002. /*............................................................
  1003. Scenario title
  1004. ............................................................*/
  1005. p = Text_String(TXT_SCENARIO_COLON);
  1006. if (ScenarioIdx != -1) {
  1007. sprintf(txt,"%s %s",p, MPlayerScenarios[ScenarioIdx]);
  1008. Fancy_Text_Print (txt, d_dialog_cx,
  1009. d_msg1_y, CC_GREEN, TBLACK,
  1010. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW | TPF_CENTER);
  1011. } else {
  1012. sprintf(txt,"%s %s",p,Text_String(TXT_NOT_FOUND));
  1013. Fancy_Text_Print (txt, d_dialog_cx,
  1014. d_msg1_y, CC_NOD_COLOR, TBLACK,
  1015. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW | TPF_CENTER);
  1016. }
  1017. /*............................................................
  1018. # of credits
  1019. ............................................................*/
  1020. p = Text_String(TXT_START_CREDITS_COLON);
  1021. sprintf(txt, "%s %d", p, MPlayerCredits);
  1022. Fancy_Text_Print (txt, d_dialog_cx,
  1023. d_msg2_y, CC_GREEN, TBLACK,
  1024. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW | TPF_CENTER);
  1025. /*............................................................
  1026. Count & Level values
  1027. ............................................................*/
  1028. p = Text_String(TXT_COUNT);
  1029. sprintf(txt,"%s %d",p,MPlayerUnitCount);
  1030. Fancy_Text_Print (txt,
  1031. d_dialog_x + (d_dialog_w / 4) - String_Pixel_Width(p),
  1032. d_msg3_y, CC_GREEN, TBLACK,
  1033. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW);
  1034. p = Text_String(TXT_LEVEL);
  1035. if (BuildLevel <= MPLAYER_BUILD_LEVEL_MAX) {
  1036. sprintf(txt, "%s %d", p, BuildLevel);
  1037. } else {
  1038. sprintf(txt, "%s **", p);
  1039. }
  1040. Fancy_Text_Print (txt,
  1041. d_dialog_x + d_dialog_w - (d_dialog_w / 4) - String_Pixel_Width(p),
  1042. d_msg3_y, CC_GREEN, TBLACK,
  1043. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW);
  1044. /*............................................................
  1045. Bases
  1046. ............................................................*/
  1047. p = Text_String(TXT_BASES_COLON);
  1048. if (MPlayerBases) {
  1049. sprintf(txt,"%s %s",p,Text_String(TXT_ON));
  1050. } else {
  1051. sprintf(txt,"%s %s",p,Text_String(TXT_OFF));
  1052. }
  1053. Fancy_Text_Print (txt,
  1054. d_dialog_x + (d_dialog_w / 4) - String_Pixel_Width(p),
  1055. d_msg4_y, CC_GREEN, TBLACK,
  1056. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW);
  1057. /*............................................................
  1058. Tiberium
  1059. ............................................................*/
  1060. p = Text_String(TXT_TIBERIUM_COLON);
  1061. if (MPlayerTiberium) {
  1062. sprintf(txt,"%s %s",p,Text_String(TXT_ON));
  1063. } else {
  1064. sprintf(txt,"%s %s",p,Text_String(TXT_OFF));
  1065. }
  1066. Fancy_Text_Print (txt,
  1067. d_dialog_x + (d_dialog_w / 4) - String_Pixel_Width(p),
  1068. d_msg5_y, CC_GREEN, TBLACK,
  1069. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW);
  1070. /*............................................................
  1071. Goody boxes
  1072. ............................................................*/
  1073. p = Text_String(TXT_CRATES_COLON);
  1074. if (MPlayerGoodies) {
  1075. sprintf(txt,"%s %s",p,Text_String(TXT_ON));
  1076. } else {
  1077. sprintf(txt,"%s %s",p,Text_String(TXT_OFF));
  1078. }
  1079. Fancy_Text_Print (txt,
  1080. d_dialog_x + d_dialog_w - (d_dialog_w / 4) - String_Pixel_Width(p),
  1081. d_msg4_y, CC_GREEN, TBLACK,
  1082. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW);
  1083. /*............................................................
  1084. Computer AI players
  1085. ............................................................*/
  1086. if (Special.IsCaptureTheFlag) {
  1087. p = Text_String(TXT_CAPTURE_THE_FLAG_COLON);
  1088. sprintf(txt,"%s %s",p,Text_String(TXT_ON));
  1089. } else {
  1090. p = Text_String(TXT_AI_PLAYERS_COLON);
  1091. if (MPlayerGhosts) {
  1092. sprintf(txt,"%s %s",p,Text_String(TXT_ON));
  1093. } else {
  1094. sprintf(txt,"%s %s",p,Text_String(TXT_OFF));
  1095. }
  1096. }
  1097. Fancy_Text_Print (txt,
  1098. d_dialog_x + d_dialog_w - (d_dialog_w / 4) - String_Pixel_Width(p),
  1099. d_msg5_y, CC_GREEN, TBLACK,
  1100. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW);
  1101. } else {
  1102. /*...............................................................
  1103. Rejection notice
  1104. ...............................................................*/
  1105. if (joinstate==JOIN_REJECTED) {
  1106. Fancy_Text_Print(TXT_REQUEST_DENIED,
  1107. d_dialog_cx, d_msg3_y, CC_GREEN, TBLACK,
  1108. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW);
  1109. }
  1110. }
  1111. }
  1112. Show_Mouse();
  1113. display = REDRAW_NONE;
  1114. }
  1115. /*
  1116. ........................... Get user input ............................
  1117. */
  1118. input = commands->Input();
  1119. /*
  1120. ---------------------------- Process input ----------------------------
  1121. */
  1122. switch (input) {
  1123. /*------------------------------------------------------------------
  1124. User clicks on a color button:
  1125. - If we've joined a game, don't allow a new color selection
  1126. - otherwise, select that color
  1127. ------------------------------------------------------------------*/
  1128. case KN_LMOUSE:
  1129. if (joinstate > JOIN_NOTHING)
  1130. break;
  1131. if (_Kbd->MouseQX > cbox_x[0] &&
  1132. _Kbd->MouseQX < (cbox_x[MAX_MPLAYER_COLORS - 1] + d_color_w) &&
  1133. _Kbd->MouseQY > d_color_y &&
  1134. _Kbd->MouseQY < (d_color_y + d_color_h)) {
  1135. MPlayerPrefColor = (_Kbd->MouseQX - cbox_x[0]) / d_color_w;
  1136. MPlayerColorIdx = MPlayerPrefColor;
  1137. name_edt.Set_Color (MPlayerTColors[MPlayerColorIdx]);
  1138. name_edt.Flag_To_Redraw();
  1139. display = REDRAW_COLORS;
  1140. }
  1141. break;
  1142. /*------------------------------------------------------------------
  1143. User clicks on the game list:
  1144. - If we've joined a game, don't allow the selected item to change;
  1145. otherwise:
  1146. - Clear the player list
  1147. - Send an immediate player query
  1148. ------------------------------------------------------------------*/
  1149. case (BUTTON_GAMELIST | KN_BUTTON):
  1150. if (joinstate==JOIN_CONFIRMED) {
  1151. gamelist.Set_Selected_Index(game_index);
  1152. } else {
  1153. if (gamelist.Current_Index() != game_index) {
  1154. Clear_Player_List (&playerlist);
  1155. game_index = gamelist.Current_Index();
  1156. Send_Join_Queries (game_index, 0, 1);
  1157. }
  1158. }
  1159. break;
  1160. /*------------------------------------------------------------------
  1161. House Buttons: set the player's desired House
  1162. ------------------------------------------------------------------*/
  1163. case (BUTTON_GDI | KN_BUTTON):
  1164. MPlayerHouse = HOUSE_GOOD;
  1165. gdibtn.Turn_On();
  1166. nodbtn.Turn_Off();
  1167. break;
  1168. case (BUTTON_NOD | KN_BUTTON):
  1169. MPlayerHouse = HOUSE_BAD;
  1170. gdibtn.Turn_Off();
  1171. nodbtn.Turn_On();
  1172. break;
  1173. /*------------------------------------------------------------------
  1174. JOIN: send a join request packet & switch to waiting-for-confirmation
  1175. mode. (Request_To_Join fills in MPlayerName with my namebuf.)
  1176. ------------------------------------------------------------------*/
  1177. case (BUTTON_JOIN | KN_BUTTON):
  1178. name_edt.Clear_Focus();
  1179. name_edt.Flag_To_Redraw();
  1180. join_index = gamelist.Current_Index();
  1181. parms_received = 0;
  1182. if (Request_To_Join (namebuf, join_index, &playerlist, MPlayerHouse,
  1183. MPlayerColorIdx)) {
  1184. joinstate = JOIN_WAIT_CONFIRM;
  1185. } else {
  1186. display = REDRAW_ALL;
  1187. }
  1188. break;
  1189. /*------------------------------------------------------------------
  1190. CANCEL: send a SIGN_OFF
  1191. - If we're part of a game, stay in this dialog; otherwise, exit
  1192. ------------------------------------------------------------------*/
  1193. case (KN_ESC):
  1194. if (Messages.Get_Edit_Buf() != NULL) {
  1195. Messages.Input(input);
  1196. display = REDRAW_MESSAGE;
  1197. break;
  1198. }
  1199. case (BUTTON_CANCEL | KN_BUTTON):
  1200. memset (&GPacket, 0, sizeof(GlobalPacketType));
  1201. GPacket.Command = NET_SIGN_OFF;
  1202. strcpy(GPacket.Name,MPlayerName);
  1203. /*...............................................................
  1204. If we're joined to a game, make extra sure the other players in
  1205. that game know I'm exiting; send my SIGN_OFF as an ack-required
  1206. packet. Do not send this packet to myself (index 0).
  1207. ...............................................................*/
  1208. if (joinstate == JOIN_CONFIRMED) {
  1209. //
  1210. // Remove myself from the player list box
  1211. //
  1212. if (playerlist.Count()) { // added: BRR 6/14/96
  1213. item = (char *)(playerlist.Get_Item(0));
  1214. playerlist.Remove_Item(item);
  1215. delete [] item;
  1216. playerlist.Flag_To_Redraw();
  1217. }
  1218. //
  1219. // Remove myself from the Players list
  1220. //
  1221. if (Players.Count()) { // added: BRR 6/14/96
  1222. who = Players[0];
  1223. Players.Delete(0);
  1224. delete who;
  1225. }
  1226. for (i = 0; i < Players.Count(); i++) {
  1227. Ipx.Send_Global_Message (&GPacket, sizeof(GlobalPacketType), 1,
  1228. &(Players[i]->Address));
  1229. Ipx.Service();
  1230. }
  1231. }
  1232. /*...............................................................
  1233. Now broadcast my SIGN_OFF so other players looking at this game
  1234. know I'm leaving.
  1235. ...............................................................*/
  1236. Ipx.Send_Global_Message (&GPacket, sizeof (GlobalPacketType),
  1237. 0, NULL);
  1238. Ipx.Send_Global_Message (&GPacket, sizeof (GlobalPacketType),
  1239. 0, NULL);
  1240. if (IsBridge) {
  1241. Ipx.Send_Global_Message (&GPacket, sizeof(GlobalPacketType), 0,
  1242. &BridgeNet);
  1243. Ipx.Send_Global_Message (&GPacket, sizeof(GlobalPacketType), 0,
  1244. &BridgeNet);
  1245. }
  1246. while (Ipx.Global_Num_Send() > 0 && Ipx.Service() != 0) ;
  1247. if (joinstate != JOIN_CONFIRMED) {
  1248. process = false;
  1249. rc = -1;
  1250. } else {
  1251. MPlayerGameName[0] = 0;
  1252. joinstate = JOIN_NOTHING;
  1253. display = REDRAW_ALL;
  1254. }
  1255. break;
  1256. /*------------------------------------------------------------------
  1257. NEW: bail out with return code 1
  1258. ------------------------------------------------------------------*/
  1259. case (BUTTON_NEW | KN_BUTTON):
  1260. /*
  1261. .................. Force user to enter a name ...................
  1262. */
  1263. if (strlen(namebuf)==0) {
  1264. CCMessageBox().Process(TXT_NAME_ERROR);
  1265. display = REDRAW_ALL;
  1266. break;
  1267. }
  1268. /*
  1269. ..................... Ensure name is unique .....................
  1270. */
  1271. found = 0;
  1272. for (i = 0; i < Games.Count(); i++) {
  1273. if (!stricmp(Games[i]->Name, namebuf)) {
  1274. found = 1;
  1275. CCMessageBox().Process (TXT_GAMENAME_MUSTBE_UNIQUE);
  1276. display = REDRAW_ALL;
  1277. break;
  1278. }
  1279. }
  1280. if (found)
  1281. break;
  1282. /*
  1283. .................... Save player & game name ....................
  1284. */
  1285. strcpy(MPlayerName,namebuf);
  1286. strcpy(MPlayerGameName,namebuf);
  1287. name_edt.Clear_Focus();
  1288. name_edt.Flag_To_Redraw();
  1289. rc = 1;
  1290. process = false;
  1291. break;
  1292. /*------------------------------------------------------------------
  1293. Default: manage the inter-player messages
  1294. ------------------------------------------------------------------*/
  1295. default:
  1296. /*...............................................................
  1297. F4/SEND/'M' = edit a message
  1298. ...............................................................*/
  1299. if (Messages.Get_Edit_Buf()==NULL) {
  1300. if ( (input == KN_M && joinstate==JOIN_CONFIRMED) ||
  1301. input==(BUTTON_SEND | KN_BUTTON) || input == KN_F4) {
  1302. memset (txt, 0, 80);
  1303. strcpy(txt,Text_String(TXT_TO_ALL)); // "To All:"
  1304. Messages.Add_Edit (MPlayerTColors[MPlayerColorIdx],
  1305. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_FULLSHADOW, txt, d_message_w-70*factor);
  1306. if (joinstate <= JOIN_NOTHING) {
  1307. name_edt.Clear_Focus();
  1308. name_edt.Flag_To_Redraw();
  1309. }
  1310. display = REDRAW_MESSAGE;
  1311. break;
  1312. }
  1313. } else
  1314. /*...............................................................
  1315. If we're already editing a message and the user clicks on
  1316. 'Send', translate our input to a Return so Messages.Input() will
  1317. work properly.
  1318. ...............................................................*/
  1319. if (input==(BUTTON_SEND | KN_BUTTON)) {
  1320. input = KN_RETURN;
  1321. }
  1322. /*...............................................................
  1323. Manage the message system (get rid of old messages)
  1324. ...............................................................*/
  1325. if (Messages.Manage()) {
  1326. display = REDRAW_MESSAGE;
  1327. }
  1328. /*...............................................................
  1329. Service keyboard input for any message being edited.
  1330. ...............................................................*/
  1331. i = Messages.Input(input);
  1332. /*...............................................................
  1333. If 'Input' returned 1, it means refresh the message display.
  1334. ...............................................................*/
  1335. if (i==1) {
  1336. Messages.Draw();
  1337. } else {
  1338. /*...............................................................
  1339. If 'Input' returned 2, it means redraw the message display.
  1340. ...............................................................*/
  1341. if (i==2) {
  1342. display = REDRAW_MESSAGE;
  1343. } else {
  1344. /*...............................................................
  1345. If 'input' returned 3, it means send the current message.
  1346. ...............................................................*/
  1347. if (i==3) {
  1348. sent_so_far = 0;
  1349. magic_number = MESSAGE_HEAD_MAGIC_NUMBER;
  1350. message_length = strlen(Messages.Get_Edit_Buf());
  1351. crc = (unsigned short)
  1352. (Calculate_CRC(Messages.Get_Edit_Buf(),message_length) &0xffff);
  1353. while ( sent_so_far < message_length ){
  1354. GPacket.Command = NET_MESSAGE;
  1355. strcpy (GPacket.Name, namebuf);
  1356. memcpy (GPacket.Message.Buf, Messages.Get_Edit_Buf()+sent_so_far, COMPAT_MESSAGE_LENGTH-5);
  1357. *(GPacket.Message.Buf + COMPAT_MESSAGE_LENGTH-5) = 0;
  1358. *((unsigned short*)(GPacket.Message.Buf + COMPAT_MESSAGE_LENGTH-4)) = magic_number;
  1359. *((unsigned short*)(GPacket.Message.Buf + COMPAT_MESSAGE_LENGTH-2)) = crc;
  1360. GPacket.Message.ID = Build_MPlayerID (MPlayerColorIdx, MPlayerHouse);
  1361. GPacket.Message.NameCRC = Compute_Name_CRC(MPlayerGameName);
  1362. /*..................................................................
  1363. Send the message to every player in our player list. The local
  1364. system will also receive this message, since it's in the Player list.
  1365. ..................................................................*/
  1366. if (joinstate == JOIN_CONFIRMED) {
  1367. for (i = 1; i < Players.Count(); i++) {
  1368. Ipx.Send_Global_Message (&GPacket,
  1369. sizeof(GlobalPacketType), 1, &(Players[i]->Address));
  1370. Ipx.Service();
  1371. }
  1372. sprintf(txt,Text_String (TXT_FROM), MPlayerName, GPacket.Message.Buf);
  1373. Messages.Add_Message (txt,
  1374. MPlayerTColors[MPlayerColorIdx],
  1375. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_FULLSHADOW, 600, magic_number, crc);
  1376. }
  1377. else {
  1378. for (i = 0; i < Players.Count(); i++) {
  1379. Ipx.Send_Global_Message (&GPacket,
  1380. sizeof(GlobalPacketType), 1, &(Players[i]->Address));
  1381. Ipx.Service();
  1382. }
  1383. }
  1384. magic_number++;
  1385. sent_so_far += COMPAT_MESSAGE_LENGTH-5;
  1386. }
  1387. }
  1388. }
  1389. }
  1390. break;
  1391. }
  1392. /*---------------------------------------------------------------------
  1393. Resend our query packets
  1394. ---------------------------------------------------------------------*/
  1395. Send_Join_Queries(game_index, 0, 0);
  1396. /*---------------------------------------------------------------------
  1397. Process incoming packets
  1398. ---------------------------------------------------------------------*/
  1399. event = Get_Join_Responses(&joinstate, &gamelist, &playerlist,
  1400. join_index);
  1401. /*.....................................................................
  1402. If we've changed state, redraw everything; if we're starting the game,
  1403. break out of the loop. If we've just joined, send out a player query
  1404. so I'll get added to the list instantly.
  1405. .....................................................................*/
  1406. if (event == EV_STATE_CHANGE) {
  1407. display = REDRAW_ALL;
  1408. if (joinstate==JOIN_GAME_START) {
  1409. rc = 0;
  1410. process = false;
  1411. } else {
  1412. /*..................................................................
  1413. If we're newly-confirmed, immediately send out a player query
  1414. ..................................................................*/
  1415. if (joinstate==JOIN_CONFIRMED) {
  1416. Clear_Player_List(&playerlist);
  1417. item = new char [MPLAYER_NAME_MAX + 4];
  1418. if (MPlayerHouse==HOUSE_GOOD) {
  1419. sprintf(item,"%s\t%s",MPlayerName,Text_String(TXT_G_D_I));
  1420. } else {
  1421. sprintf(item,"%s\t%s",MPlayerName,Text_String(TXT_N_O_D));
  1422. }
  1423. playerlist.Add_Item (item, MPlayerTColors[MPlayerColorIdx]);
  1424. who = new NodeNameType;
  1425. strcpy(who->Name, MPlayerName);
  1426. who->Address = IPXAddressClass();
  1427. who->Player.House = MPlayerHouse;
  1428. who->Player.Color = MPlayerColorIdx;
  1429. Players.Add (who);
  1430. Send_Join_Queries (game_index, 0, 1);
  1431. } else {
  1432. /*..................................................................
  1433. If we've been rejected, clear any messages we may have been typing.
  1434. ..................................................................*/
  1435. if (joinstate==JOIN_REJECTED) {
  1436. //
  1437. // Remove myself from the player list box
  1438. //
  1439. if (playerlist.Count()) { // added: BRR 6/14/96
  1440. item = (char *)(playerlist.Get_Item(0));
  1441. if (item){
  1442. playerlist.Remove_Item(item);
  1443. delete [] item;
  1444. playerlist.Flag_To_Redraw();
  1445. }
  1446. }
  1447. //
  1448. // Remove myself from the Players list
  1449. //
  1450. if (Players.Count()){
  1451. who = Players[0];
  1452. Players.Delete(0);
  1453. delete who;
  1454. }
  1455. Messages.Init (d_message_x + 2, d_message_y + 2, 4,
  1456. MAX_MESSAGE_LENGTH, d_txt6_h);
  1457. }
  1458. }
  1459. }
  1460. } else
  1461. /*.....................................................................
  1462. If a new game is detected, and it's the first game on our list,
  1463. automatically send out a player query for that game.
  1464. .....................................................................*/
  1465. if (event == EV_NEW_GAME && gamelist.Count()==1) {
  1466. gamelist.Set_Selected_Index(0);
  1467. game_index = gamelist.Current_Index();
  1468. Send_Join_Queries (game_index, 0, 1);
  1469. } else
  1470. /*.....................................................................
  1471. If the game options have changed, print them.
  1472. .....................................................................*/
  1473. if (event == EV_GAME_OPTIONS) {
  1474. parms_received = 1;
  1475. display = REDRAW_MESSAGE;
  1476. } else
  1477. /*.....................................................................
  1478. Draw an incoming message
  1479. .....................................................................*/
  1480. if (event == EV_MESSAGE) {
  1481. display = REDRAW_MESSAGE;
  1482. } else
  1483. /*.....................................................................
  1484. A game before the one I've selected is gone, so we have a new index now.
  1485. 'game_index' must be kept set to the currently-selected list item, so
  1486. we send out queries for the currently-selected game. It's therefore
  1487. imperative that we detect any changes to the game list.
  1488. If we're joined in a game, we must decrement our game_index to keep
  1489. it aligned with the game we're joined to.
  1490. .....................................................................*/
  1491. if (event == EV_GAME_SIGNOFF) {
  1492. if (joinstate==JOIN_CONFIRMED) {
  1493. game_index--;
  1494. join_index--;
  1495. gamelist.Set_Selected_Index(join_index);
  1496. } else {
  1497. gamelist.Flag_To_Redraw();
  1498. Clear_Player_List(&playerlist);
  1499. game_index = gamelist.Current_Index();
  1500. Send_Join_Queries (game_index, 0, 1);
  1501. }
  1502. }
  1503. /*---------------------------------------------------------------------
  1504. Service the Ipx connections
  1505. ---------------------------------------------------------------------*/
  1506. Ipx.Service();
  1507. /*---------------------------------------------------------------------
  1508. Clean out the Game List; if an old entry is found:
  1509. - Remove it
  1510. - Clear the player list
  1511. - Send queries for the new selected game, if there is one
  1512. ---------------------------------------------------------------------*/
  1513. for (i = 0; i < Games.Count(); i++) {
  1514. if (TickCount.Time() - Games[i]->Game.LastTime > 400) {
  1515. Games.Delete(Games[i]);
  1516. item = (char *)(gamelist.Get_Item (i));
  1517. gamelist.Remove_Item (item);
  1518. delete [] item;
  1519. if (i <= game_index) {
  1520. gamelist.Flag_To_Redraw();
  1521. Clear_Player_List(&playerlist);
  1522. game_index = gamelist.Current_Index();
  1523. Send_Join_Queries (game_index, 0, 1);
  1524. }
  1525. }
  1526. }
  1527. /*---------------------------------------------------------------------
  1528. Service the sounds & score; GameActive must be false at this point,
  1529. so Call_Back() doesn't intercept global messages from me!
  1530. ---------------------------------------------------------------------*/
  1531. Call_Back();
  1532. }
  1533. /*------------------------------------------------------------------------
  1534. Establish connections with all other players.
  1535. ------------------------------------------------------------------------*/
  1536. if (rc == 0) {
  1537. /*.....................................................................
  1538. If the other guys are playing a scenario I don't have (sniff), I can't
  1539. play. Try to bail gracefully.
  1540. .....................................................................*/
  1541. if (ScenarioIdx==-1) {
  1542. CCMessageBox().Process (TXT_UNABLE_PLAY_WAAUGH);
  1543. //
  1544. // Remove myself from the player list box
  1545. //
  1546. if (playerlist.Count()) { // added: BRR 6/14/96
  1547. item = (char *)(playerlist.Get_Item(0));
  1548. playerlist.Remove_Item(item);
  1549. delete [] item;
  1550. playerlist.Flag_To_Redraw();
  1551. }
  1552. //
  1553. // Remove myself from the Players list
  1554. //
  1555. if (Players.Count()) { // added: BRR 6/14/96
  1556. who = Players[0];
  1557. Players.Delete(0);
  1558. delete who;
  1559. }
  1560. memset (&GPacket, 0, sizeof(GlobalPacketType));
  1561. GPacket.Command = NET_SIGN_OFF;
  1562. strcpy (GPacket.Name, MPlayerName);
  1563. for (i = 0; i < Players.Count(); i++) {
  1564. Ipx.Send_Global_Message (&GPacket, sizeof(GlobalPacketType), 1,
  1565. &(Players[i]->Address));
  1566. Ipx.Service();
  1567. }
  1568. Ipx.Send_Global_Message (&GPacket, sizeof (GlobalPacketType),
  1569. 0, NULL);
  1570. Ipx.Send_Global_Message (&GPacket, sizeof (GlobalPacketType),
  1571. 0, NULL);
  1572. if (IsBridge) {
  1573. Ipx.Send_Global_Message (&GPacket, sizeof(GlobalPacketType), 0,
  1574. &BridgeNet);
  1575. Ipx.Send_Global_Message (&GPacket, sizeof(GlobalPacketType), 0,
  1576. &BridgeNet);
  1577. }
  1578. while (Ipx.Global_Num_Send() > 0 && Ipx.Service() != 0) ;
  1579. rc = -1;
  1580. } else {
  1581. /*..................................................................
  1582. Set the number of players in this game, and my ID
  1583. ..................................................................*/
  1584. MPlayerCount = Players.Count();
  1585. MPlayerLocalID = Build_MPlayerID (MPlayerColorIdx, MPlayerHouse);
  1586. /*..................................................................
  1587. Get the scenario number
  1588. ..................................................................*/
  1589. Scenario = MPlayerFilenum[ScenarioIdx];
  1590. /*..................................................................
  1591. Form connections with all other players. Form the IPX Connection ID
  1592. from the player's Color and House. This will let us extract any
  1593. player's color & house at any time. Fill in 'tmp_id' while we're
  1594. doing this.
  1595. ..................................................................*/
  1596. for (i = 0; i < Players.Count(); i++) {
  1597. /*...............................................................
  1598. Only create the connection if it's not myself!
  1599. ...............................................................*/
  1600. if (strcmp (MPlayerName, Players[i]->Name)) {
  1601. id = Build_MPlayerID(Players[i]->Player.Color,
  1602. Players[i]->Player.House);
  1603. tmp_id[i] = id;
  1604. Ipx.Create_Connection((int)id, Players[i]->Name, &(Players[i]->Address) );
  1605. } else {
  1606. tmp_id[i] = MPlayerLocalID;
  1607. }
  1608. }
  1609. /*..................................................................
  1610. Store every player's ID in the MPlayerID[] array. This array will
  1611. determine the order of event execution, so the ID's must be stored
  1612. in the same order on all systems.
  1613. ..................................................................*/
  1614. for (i = 0; i < MPlayerCount; i++) {
  1615. min_index = 0;
  1616. min_id = 0xff;
  1617. for (j = 0; j < MPlayerCount; j++) {
  1618. if (tmp_id[j] < min_id) {
  1619. min_id = tmp_id[j];
  1620. min_index = j;
  1621. }
  1622. }
  1623. MPlayerID[i] = tmp_id[min_index];
  1624. tmp_id[min_index] = 0xff;
  1625. }
  1626. /*..................................................................
  1627. Fill in the array of player names, including my own.
  1628. ..................................................................*/
  1629. for (i = 0; i < MPlayerCount; i++) {
  1630. if (MPlayerID[i] == MPlayerLocalID) {
  1631. strcpy (MPlayerNames[i], MPlayerName);
  1632. } else {
  1633. strcpy (MPlayerNames[i], Ipx.Connection_Name(MPlayerID[i]));
  1634. }
  1635. }
  1636. }
  1637. /*---------------------------------------------------------------------
  1638. Wait a while, polling the IPX service routines, to give our ACK
  1639. a chance to get to the other system. If he doesn't get our ACK, he'll
  1640. be waiting the whole time we load MIX files.
  1641. ---------------------------------------------------------------------*/
  1642. i = MAX(Ipx.Global_Response_Time() * 2, 60);
  1643. starttime = TickCount.Time();
  1644. while (TickCount.Time() - starttime < i) {
  1645. Ipx.Service();
  1646. }
  1647. }
  1648. /*------------------------------------------------------------------------
  1649. Init network timing values, using previous response times as a measure
  1650. of what our retry delta & timeout should be.
  1651. ------------------------------------------------------------------------*/
  1652. Ipx.Set_Timing (Ipx.Global_Response_Time() + 2, -1,
  1653. Ipx.Global_Response_Time() * 4);
  1654. /*------------------------------------------------------------------------
  1655. Clear all lists
  1656. ------------------------------------------------------------------------*/
  1657. Clear_Game_List(&gamelist);
  1658. Clear_Player_List(&playerlist);
  1659. /*------------------------------------------------------------------------
  1660. Restore screen
  1661. ------------------------------------------------------------------------*/
  1662. Hide_Mouse();
  1663. Load_Title_Screen("HTITLE.PCX", &HidPage, Palette);
  1664. HidPage.Blit(SeenBuff);
  1665. Show_Mouse();
  1666. return(rc);
  1667. }
  1668. /***************************************************************************
  1669. * Clear_Game_List -- Clears the game-name listbox & 'Games' Vector *
  1670. * *
  1671. * Assumes each entry in 'Games' & the list box have been allocated *
  1672. * separately. *
  1673. * *
  1674. * INPUT: *
  1675. * gamelist ptr to list box *
  1676. * *
  1677. * OUTPUT: *
  1678. * none *
  1679. * *
  1680. * WARNINGS: *
  1681. * none *
  1682. * *
  1683. * HISTORY: *
  1684. *=========================================================================*/
  1685. static void Clear_Game_List (ListClass *gamelist)
  1686. {
  1687. char * item;
  1688. int i;
  1689. /*------------------------------------------------------------------------
  1690. Clear the list box
  1691. ------------------------------------------------------------------------*/
  1692. while (gamelist->Count()) {
  1693. item = (char *)(gamelist->Get_Item (0));
  1694. gamelist->Remove_Item(item);
  1695. delete [] item;
  1696. }
  1697. gamelist->Flag_To_Redraw();
  1698. /*------------------------------------------------------------------------
  1699. Clear the 'Games' Vector
  1700. ------------------------------------------------------------------------*/
  1701. for (i = 0; i < Games.Count(); i++)
  1702. delete Games[i];
  1703. Games.Clear();
  1704. } /* end of Clear_Game_List */
  1705. /***************************************************************************
  1706. * Clear_Player_List -- Clears the player-name listbox & Vector *
  1707. * *
  1708. * Assumes each entry in 'Players' & the list box have been allocated *
  1709. * separately. *
  1710. * *
  1711. * INPUT: *
  1712. * playerlist ptr to list box *
  1713. * *
  1714. * OUTPUT: *
  1715. * none *
  1716. * *
  1717. * WARNINGS: *
  1718. * none *
  1719. * *
  1720. * HISTORY: *
  1721. *=========================================================================*/
  1722. static void Clear_Player_List (ListClass *playerlist)
  1723. {
  1724. char * item;
  1725. int i;
  1726. /*------------------------------------------------------------------------
  1727. Clear the list box
  1728. ------------------------------------------------------------------------*/
  1729. while (playerlist->Count()) {
  1730. item = (char *)(playerlist->Get_Item(0));
  1731. playerlist->Remove_Item(item);
  1732. delete [] item;
  1733. }
  1734. playerlist->Flag_To_Redraw();
  1735. /*------------------------------------------------------------------------
  1736. Clear the 'Players' Vector
  1737. ------------------------------------------------------------------------*/
  1738. for (i = 0; i < Players.Count(); i++)
  1739. delete Players[i];
  1740. Players.Clear();
  1741. } /* end of Clear_Player_List */
  1742. /***************************************************************************
  1743. * Request_To_Join -- Sends a JOIN request packet to game owner *
  1744. * *
  1745. * Regardless of the return code, the Join Dialog will need to be redrawn *
  1746. * after calling this routine. *
  1747. * *
  1748. * INPUT: *
  1749. * playername player's name *
  1750. * join_index index of game we're joining *
  1751. * playerlist listbox containing other players' names *
  1752. * house requested house *
  1753. * color requested color *
  1754. * *
  1755. * OUTPUT: *
  1756. * 1 = Packet sent, 0 = wasn't *
  1757. * *
  1758. * WARNINGS: *
  1759. * none. *
  1760. * *
  1761. * HISTORY: *
  1762. *=========================================================================*/
  1763. static int Request_To_Join (char *playername, int join_index, ListClass *playerlist,
  1764. HousesType house, int color)
  1765. {
  1766. int i;
  1767. playerlist = playerlist; // shaddup, Mr stupid compiler!
  1768. /*
  1769. --------------------------- Validate join_index --------------------------
  1770. */
  1771. if ( (Games.Count()==0) || join_index > Games.Count() || join_index < 0) {
  1772. CCMessageBox().Process (TXT_NOTHING_TO_JOIN);
  1773. return(false);
  1774. }
  1775. /*
  1776. ----------------------- Force user to enter a name -----------------------
  1777. */
  1778. if (strlen(playername)==0) {
  1779. CCMessageBox().Process (TXT_NAME_ERROR);
  1780. return(false);
  1781. }
  1782. /*
  1783. ------------------------- The game must be open --------------------------
  1784. */
  1785. if (!Games[join_index]->Game.IsOpen) {
  1786. CCMessageBox().Process(TXT_GAME_IS_CLOSED);
  1787. return (false);
  1788. }
  1789. /*
  1790. ------------------------ Make sure name is unique ------------------------
  1791. */
  1792. for (i = 0; i < Players.Count(); i++) {
  1793. if (!stricmp(playername, Players[i]->Name)) {
  1794. CCMessageBox().Process (TXT_NAME_MUSTBE_UNIQUE);
  1795. return(false);
  1796. }
  1797. }
  1798. /*
  1799. ----------------------------- Check version #'s --------------------------
  1800. */
  1801. int v;
  1802. #ifdef PATCH
  1803. if (IsV107) {
  1804. v = 1;
  1805. } else {
  1806. v = 2;
  1807. }
  1808. #else
  1809. v = Version_Number();
  1810. #endif
  1811. if (Games[join_index]->Game.Version > v) {
  1812. CCMessageBox().Process (TXT_YOURGAME_OUTDATED);
  1813. return(false);
  1814. } else {
  1815. if (Games[join_index]->Game.Version < v) {
  1816. CCMessageBox().Process (TXT_DESTGAME_OUTDATED);
  1817. return(false);
  1818. }
  1819. }
  1820. /*
  1821. ----------------------------- Save game name -----------------------------
  1822. */
  1823. strcpy (MPlayerName,playername);
  1824. /*
  1825. ----------------------- Send packet to game's owner ----------------------
  1826. */
  1827. memset (&GPacket, 0, sizeof(GlobalPacketType));
  1828. GPacket.Command = NET_QUERY_JOIN;
  1829. strcpy (GPacket.Name, MPlayerName);
  1830. GPacket.PlayerInfo.House = house;
  1831. GPacket.PlayerInfo.Color = color;
  1832. Ipx.Send_Global_Message (&GPacket, sizeof(GlobalPacketType), 1,
  1833. &(Games[join_index]->Address));
  1834. return(true);
  1835. }
  1836. /***********************************************************************************************
  1837. * Send_Join_Queries -- sends queries for the Join Dialog *
  1838. * *
  1839. * This routine [re]sends the queries related to the Join Dialog: *
  1840. * - NET_QUERY_GAME *
  1841. * - NET_QUERY_PLAYER for the game currently selected (if there is one) *
  1842. * *
  1843. * The queries are "staggered" in time so they aren't all sent at once; otherwise, we'd *
  1844. * be inundated with reply packets & we'd miss some (even though the replies will require *
  1845. * ACK's). *
  1846. * *
  1847. * INPUT: *
  1848. * curgame index of currently-selected game; -1 = none *
  1849. * gamenow if 1, will immediately send the game query *
  1850. * playernow if 1, will immediately send the player query for currently-selected game *
  1851. * *
  1852. * OUTPUT: *
  1853. * none. *
  1854. * *
  1855. * WARNINGS: *
  1856. * none. *
  1857. * *
  1858. * HISTORY: *
  1859. * 02/14/1995 BR : Created. *
  1860. * 04/15/1995 BRR : Created. *
  1861. *=============================================================================================*/
  1862. static void Send_Join_Queries(int curgame, int gamenow, int playernow)
  1863. {
  1864. static int lasttime1 = 0; // time since last Game query sent out
  1865. static int lasttime2 = 0; // time since last Player query sent out
  1866. /*------------------------------------------------------------------------
  1867. Send the game-name query if the time has expired, or we're told to do
  1868. it right now
  1869. ------------------------------------------------------------------------*/
  1870. if ( (TickCount.Time() - lasttime1 > 120) || gamenow) {
  1871. lasttime1 = TickCount.Time();
  1872. memset (&GPacket, 0, sizeof(GlobalPacketType));
  1873. GPacket.Command = NET_QUERY_GAME;
  1874. Ipx.Send_Global_Message (&GPacket, sizeof(GlobalPacketType), 0, NULL);
  1875. /*.....................................................................
  1876. If the user specified a remote server address, broadcast over that
  1877. network, too.
  1878. .....................................................................*/
  1879. if (IsBridge)
  1880. Ipx.Send_Global_Message (&GPacket, sizeof(GlobalPacketType), 0,
  1881. &BridgeNet);
  1882. }
  1883. /*------------------------------------------------------------------------
  1884. Send the player query for the game currently clicked on, if the time has
  1885. expired and there is a currently-selected game, or we're told to do it
  1886. right now
  1887. ------------------------------------------------------------------------*/
  1888. if ( (curgame != -1) && curgame < Games.Count() &&
  1889. ((TickCount.Time() - lasttime2 > 35) || playernow) ) {
  1890. lasttime2 = TickCount.Time();
  1891. memset (&GPacket, 0, sizeof(GlobalPacketType));
  1892. GPacket.Command = NET_QUERY_PLAYER;
  1893. strcpy (GPacket.Name, Games[curgame]->Name);
  1894. Ipx.Send_Global_Message (&GPacket, sizeof(GlobalPacketType), 0, NULL);
  1895. /*.....................................................................
  1896. If the user specified a remote server address, broadcast over that
  1897. network, too.
  1898. .....................................................................*/
  1899. if (IsBridge)
  1900. Ipx.Send_Global_Message (&GPacket, sizeof(GlobalPacketType), 0,
  1901. &BridgeNet);
  1902. }
  1903. } /* end of Send_Join_Queries */
  1904. /***********************************************************************************************
  1905. * Get_Join_Responses -- sends queries for the Join Dialog *
  1906. * *
  1907. * This routine polls the Global Channel to see if there are any incoming packets; *
  1908. * if so, it processes them. This routine can change the state of the Join Dialog, or *
  1909. * the contents of the list boxes, based on what the packet is. *
  1910. * *
  1911. * The list boxes are passed in as pointers; they can't be made globals, because they *
  1912. * can't be constructed, because they require shape pointers to the arrow buttons, and *
  1913. * the mix files won't have been initialized when the global variables' constructors are *
  1914. * called. *
  1915. * *
  1916. * This routine sets the globals *
  1917. * MPlayerHouse (from NET_CONFIRM_JOIN) *
  1918. * MPlayerColorIdx (from NET_CONFIRM_JOIN) *
  1919. * MPlayerBases (from NET_GAME_OPTIONS) *
  1920. * MPlayerTiberium (from NET_GAME_OPTIONS) *
  1921. * MPlayerGoodies (from NET_GAME_OPTIONS) *
  1922. * MPlayerGhosts (from NET_GAME_OPTIONS) *
  1923. * ScenarioIdx (from NET_GAME_OPTIONS; -1 = scenario not found) *
  1924. * *
  1925. * INPUT: *
  1926. * joinstate current state of Join Dialog *
  1927. * gamelist list box containing game names *
  1928. * playerlist list box containing player names for the currently-selected game *
  1929. * join_index index of the game we've joined or are asking to join *
  1930. * *
  1931. * OUTPUT: *
  1932. * Event that occurred *
  1933. * *
  1934. * WARNINGS: *
  1935. * none. *
  1936. * *
  1937. * HISTORY: *
  1938. * 02/14/1995 BR : Created. *
  1939. * 04/15/1995 BRR : Created. *
  1940. *=============================================================================================*/
  1941. static JoinEventType Get_Join_Responses(JoinStateType *joinstate, ListClass *gamelist,
  1942. ColorListClass *playerlist, int join_index)
  1943. {
  1944. int rc;
  1945. char * item; // general-purpose string
  1946. NodeNameType *who; // node to add to Games or Players
  1947. int i;
  1948. int found;
  1949. JoinEventType retcode = EV_NONE;
  1950. char txt[80];
  1951. int color;
  1952. unsigned short magic_number;
  1953. unsigned short crc;
  1954. /*------------------------------------------------------------------------
  1955. If there is no incoming packet, just return
  1956. ------------------------------------------------------------------------*/
  1957. rc = Ipx.Get_Global_Message (&GPacket, &GPacketlen, &GAddress, &GProductID);
  1958. if (!rc || GProductID != IPXGlobalConnClass::COMMAND_AND_CONQUER)
  1959. return(EV_NONE);
  1960. /*------------------------------------------------------------------------
  1961. If we're joined in a game, handle the packet in a standard way; otherwise,
  1962. don't answer standard queries.
  1963. ------------------------------------------------------------------------*/
  1964. if ( (*joinstate)==JOIN_CONFIRMED &&
  1965. Process_Global_Packet(&GPacket,&GAddress)!=0)
  1966. return(EV_NONE);
  1967. /*------------------------------------------------------------------------
  1968. NET_ANSWER_GAME: Another system is answering our GAME query, so add that
  1969. system to our list box if it's new.
  1970. ------------------------------------------------------------------------*/
  1971. if (GPacket.Command==NET_ANSWER_GAME) {
  1972. /*.....................................................................
  1973. See if this name is unique
  1974. .....................................................................*/
  1975. retcode = EV_NONE;
  1976. found = 0;
  1977. for (i = 0; i < Games.Count(); i++) {
  1978. if (!strcmp(Games[i]->Name, GPacket.Name)) {
  1979. found = 1;
  1980. /*...............................................................
  1981. If name was found, update the node's time stamp & IsOpen flag.
  1982. ...............................................................*/
  1983. Games[i]->Game.LastTime = TickCount.Time();
  1984. if (Games[i]->Game.IsOpen != GPacket.GameInfo.IsOpen) {
  1985. item = (char *)gamelist->Get_Item(i);
  1986. if (GPacket.GameInfo.IsOpen) {
  1987. sprintf(item,Text_String(TXT_THATGUYS_GAME),GPacket.Name);
  1988. } else {
  1989. sprintf(item,Text_String(TXT_THATGUYS_GAME_BRACKET),GPacket.Name);
  1990. }
  1991. Games[i]->Game.IsOpen = GPacket.GameInfo.IsOpen;
  1992. gamelist->Flag_To_Redraw();
  1993. /*............................................................
  1994. If this game has gone from closed to open, copy the responder's
  1995. address into our Game slot, since the guy responding to this
  1996. must be game owner.
  1997. ............................................................*/
  1998. if (Games[i]->Game.IsOpen)
  1999. Games[i]->Address = GAddress;
  2000. }
  2001. break;
  2002. }
  2003. }
  2004. /*.....................................................................
  2005. name not found (or addresses are different); add it to 'Games'
  2006. .....................................................................*/
  2007. if (found==0) {
  2008. /*..................................................................
  2009. Create a new node structure, fill it in, add it to 'Games'
  2010. ..................................................................*/
  2011. who = new NodeNameType;
  2012. strcpy(who->Name, GPacket.Name);
  2013. who->Address = GAddress;
  2014. who->Game.Version = GPacket.GameInfo.Version;
  2015. who->Game.IsOpen = GPacket.GameInfo.IsOpen;
  2016. who->Game.LastTime = TickCount.Time();
  2017. Games.Add (who);
  2018. /*..................................................................
  2019. Create a string for "xxx's Game", leaving room for brackets around
  2020. the string if it's a closed game
  2021. ..................................................................*/
  2022. item = new char [MPLAYER_NAME_MAX + 9];
  2023. if (GPacket.GameInfo.IsOpen) {
  2024. sprintf(item,Text_String(TXT_THATGUYS_GAME),GPacket.Name);
  2025. } else {
  2026. sprintf(item,Text_String(TXT_THATGUYS_GAME_BRACKET),GPacket.Name);
  2027. }
  2028. gamelist->Add_Item(item);
  2029. retcode = EV_NEW_GAME;
  2030. }
  2031. }
  2032. /*------------------------------------------------------------------------
  2033. NET_ANSWER_PLAYER: Another system is answering our PLAYER query, so add it
  2034. to our player list box & the Player Vector if it's new
  2035. ------------------------------------------------------------------------*/
  2036. else if (GPacket.Command==NET_ANSWER_PLAYER) {
  2037. /*.....................................................................
  2038. See if this name is unique
  2039. .....................................................................*/
  2040. retcode = EV_NONE;
  2041. found = 0;
  2042. for (i = 0; i < Players.Count(); i++) {
  2043. /*..................................................................
  2044. If the address is already present, re-copy their name, color &
  2045. house into the existing entry, in case they've changed it without
  2046. our knowledge; set the 'found' flag so we won't create a new entry.
  2047. ..................................................................*/
  2048. if (Players[i]->Address==GAddress) {
  2049. strcpy(Players[i]->Name, GPacket.Name);
  2050. Players[i]->Player.House = GPacket.PlayerInfo.House;
  2051. Players[i]->Player.Color = GPacket.PlayerInfo.Color;
  2052. playerlist->Colors[i] = MPlayerTColors[GPacket.PlayerInfo.Color];
  2053. found = 1;
  2054. break;
  2055. }
  2056. }
  2057. /*.....................................................................
  2058. Don't add this player if he's not part of the game that's selected.
  2059. .....................................................................*/
  2060. i = gamelist->Current_Index();
  2061. if (Games.Count() && GPacket.PlayerInfo.NameCRC != Compute_Name_CRC(Games[i]->Name))
  2062. found = 1;
  2063. /*
  2064. ** Dont add this player if its really me! (hack, hack)
  2065. */
  2066. if (!strcmp(GPacket.Name, MPlayerName)){
  2067. found = 1;
  2068. }
  2069. /*.....................................................................
  2070. name not found (or address didn't match); add to player list box & Vector
  2071. .....................................................................*/
  2072. if (found==0) {
  2073. /*..................................................................
  2074. Create & add a node to the Vector
  2075. ..................................................................*/
  2076. who = new NodeNameType;
  2077. strcpy(who->Name, GPacket.Name);
  2078. who->Address = GAddress;
  2079. who->Player.House = GPacket.PlayerInfo.House;
  2080. who->Player.Color = GPacket.PlayerInfo.Color;
  2081. Players.Add (who);
  2082. /*..................................................................
  2083. Create & add a string to the list box
  2084. ..................................................................*/
  2085. item = new char [MPLAYER_NAME_MAX + 4];
  2086. if (GPacket.PlayerInfo.House==HOUSE_GOOD) {
  2087. sprintf(item,"%s\t%s",GPacket.Name,Text_String(TXT_G_D_I));
  2088. } else {
  2089. sprintf(item,"%s\t%s",GPacket.Name,Text_String(TXT_N_O_D));
  2090. }
  2091. playerlist->Add_Item(item, MPlayerTColors[who->Player.Color]);
  2092. retcode = EV_NEW_PLAYER;
  2093. }
  2094. }
  2095. /*------------------------------------------------------------------------
  2096. NET_CONFIRM_JOIN: The game owner has confirmed our JOIN query; mark us as
  2097. being confirmed, and start answering queries from other systems
  2098. ------------------------------------------------------------------------*/
  2099. else if (GPacket.Command==NET_CONFIRM_JOIN) {
  2100. if ( (*joinstate) != JOIN_CONFIRMED) {
  2101. strcpy (MPlayerGameName, GPacket.Name);
  2102. MPlayerHouse = GPacket.PlayerInfo.House;
  2103. MPlayerColorIdx = GPacket.PlayerInfo.Color;
  2104. (*joinstate) = JOIN_CONFIRMED;
  2105. retcode = EV_STATE_CHANGE;
  2106. }
  2107. }
  2108. /*------------------------------------------------------------------------
  2109. NET_REJECT_JOIN: The game owner has turned down our JOIN query; restore
  2110. the dialog state to its first pop-up state. Broadcast a sign-off to
  2111. tell all other systems that I'm no longer a part of any game; this way,
  2112. I'll be properly removed from their dialogs.
  2113. ------------------------------------------------------------------------*/
  2114. else if (GPacket.Command==NET_REJECT_JOIN) {
  2115. if ( (*joinstate) != JOIN_REJECTED) {
  2116. memset (&GPacket, 0, sizeof(GlobalPacketType));
  2117. GPacket.Command = NET_SIGN_OFF;
  2118. strcpy (GPacket.Name,MPlayerName);
  2119. Ipx.Send_Global_Message (&GPacket, sizeof (GlobalPacketType), 0, NULL);
  2120. Ipx.Send_Global_Message (&GPacket, sizeof (GlobalPacketType), 0, NULL);
  2121. if (IsBridge) {
  2122. Ipx.Send_Global_Message (&GPacket, sizeof(GlobalPacketType), 0,
  2123. &BridgeNet);
  2124. Ipx.Send_Global_Message (&GPacket, sizeof(GlobalPacketType), 0,
  2125. &BridgeNet);
  2126. }
  2127. while (Ipx.Global_Num_Send() > 0 && Ipx.Service() != 0) ;
  2128. MPlayerGameName[0] = 0;
  2129. (*joinstate) = JOIN_REJECTED;
  2130. retcode = EV_STATE_CHANGE;
  2131. }
  2132. }
  2133. /*------------------------------------------------------------------------
  2134. NET_GAME_OPTIONS: The game owner has changed the game options & is sending
  2135. us the new values.
  2136. ------------------------------------------------------------------------*/
  2137. else if (GPacket.Command==NET_GAME_OPTIONS) {
  2138. if ( (*joinstate)==JOIN_CONFIRMED) {
  2139. MPlayerCredits = GPacket.ScenarioInfo.Credits;
  2140. MPlayerBases = GPacket.ScenarioInfo.IsBases;
  2141. MPlayerTiberium = GPacket.ScenarioInfo.IsTiberium;
  2142. MPlayerGoodies = GPacket.ScenarioInfo.IsGoodies;
  2143. MPlayerGhosts = GPacket.ScenarioInfo.IsGhosties;
  2144. BuildLevel = GPacket.ScenarioInfo.BuildLevel;
  2145. MPlayerUnitCount = GPacket.ScenarioInfo.UnitCount;
  2146. Seed = GPacket.ScenarioInfo.Seed;
  2147. Special = GPacket.ScenarioInfo.Special;
  2148. Options.GameSpeed = GPacket.ScenarioInfo.GameSpeed;
  2149. if (MPlayerTiberium) {
  2150. Special.IsTGrowth = 1;
  2151. Special.IsTSpread = 1;
  2152. } else {
  2153. Special.IsTGrowth = 0;
  2154. Special.IsTSpread = 0;
  2155. }
  2156. if (Winsock.Get_Connected()){
  2157. ScenarioIdx = GPacket.ScenarioInfo.Scenario;
  2158. }else{
  2159. ScenarioIdx = -1;
  2160. for (i = 0; i < MPlayerFilenum.Count(); i++) {
  2161. if (GPacket.ScenarioInfo.Scenario == MPlayerFilenum[i])
  2162. ScenarioIdx = i;
  2163. }
  2164. }
  2165. retcode = EV_GAME_OPTIONS;
  2166. }
  2167. }
  2168. /*------------------------------------------------------------------------
  2169. NET_SIGN_OFF: Another system is signing off: search for that system in
  2170. both the game list & player list, & remove it if found
  2171. ------------------------------------------------------------------------*/
  2172. else if (GPacket.Command==NET_SIGN_OFF) {
  2173. /*.....................................................................
  2174. Remove this name from the list of games
  2175. .....................................................................*/
  2176. for (i = 0; i < Games.Count(); i++) {
  2177. if (!strcmp(Games[i]->Name, GPacket.Name) &&
  2178. Games[i]->Address==GAddress) {
  2179. /*...............................................................
  2180. If the system signing off is the currently-selected list
  2181. item, clear the player list since that game is no longer
  2182. forming.
  2183. ...............................................................*/
  2184. if (i==gamelist->Current_Index()) {
  2185. Clear_Player_List (playerlist);
  2186. }
  2187. /*...............................................................
  2188. If the system signing off was the owner of our game, mark
  2189. ourselves as rejected
  2190. ...............................................................*/
  2191. if ( (*joinstate) > JOIN_NOTHING && i==join_index) {
  2192. (*joinstate) = JOIN_REJECTED;
  2193. retcode = EV_STATE_CHANGE;
  2194. }
  2195. /*
  2196. ....................... Set my return code ......................
  2197. */
  2198. if (retcode == EV_NONE) {
  2199. if (i <= gamelist->Current_Index()) {
  2200. retcode = EV_GAME_SIGNOFF;
  2201. } else {
  2202. retcode = EV_PLAYER_SIGNOFF;
  2203. }
  2204. }
  2205. /*
  2206. ................. Remove game name from game list ...............
  2207. */
  2208. Games.Delete(Games[i]);
  2209. item = (char *)(gamelist->Get_Item (i));
  2210. gamelist->Remove_Item (item);
  2211. delete [] item;
  2212. gamelist->Flag_To_Redraw();
  2213. }
  2214. }
  2215. /*.....................................................................
  2216. Remove this name from the list of players
  2217. .....................................................................*/
  2218. for (i = 0; i < Players.Count(); i++) {
  2219. /*
  2220. ..................... Name found; remove it .....................
  2221. */
  2222. if (Players[i]->Address==GAddress) {
  2223. item = (char *)(playerlist->Get_Item(i));
  2224. playerlist->Remove_Item(item);
  2225. delete [] item;
  2226. Players.Delete(Players[i]);
  2227. playerlist->Flag_To_Redraw();
  2228. if (retcode == EV_NONE)
  2229. retcode = EV_PLAYER_SIGNOFF;
  2230. }
  2231. }
  2232. }
  2233. /*------------------------------------------------------------------------
  2234. NET_GO: The game's owner is signalling us to start playing.
  2235. ------------------------------------------------------------------------*/
  2236. else if (GPacket.Command==NET_GO) {
  2237. if ( (*joinstate)==JOIN_CONFIRMED) {
  2238. MPlayerMaxAhead = GPacket.ResponseTime.OneWay;
  2239. (*joinstate) = JOIN_GAME_START;
  2240. retcode = EV_STATE_CHANGE;
  2241. CCDebugString ("C&C95 - Received the 'GO' packet\n");
  2242. }
  2243. }
  2244. /*------------------------------------------------------------------------
  2245. NET_MESSAGE: Someone is sending us a message
  2246. ------------------------------------------------------------------------*/
  2247. else if (GPacket.Command==NET_MESSAGE) {
  2248. sprintf(txt,Text_String (TXT_FROM), GPacket.Name, GPacket.Message.Buf);
  2249. magic_number = *((unsigned short*)(GPacket.Message.Buf + COMPAT_MESSAGE_LENGTH-4));
  2250. crc = *((unsigned short*)(GPacket.Message.Buf + COMPAT_MESSAGE_LENGTH-2));
  2251. color = MPlayerID_To_ColorIndex(GPacket.Message.ID);
  2252. Messages.Add_Message (txt, MPlayerTColors[color],
  2253. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_FULLSHADOW, 1200, magic_number, crc);
  2254. retcode = EV_MESSAGE;
  2255. }
  2256. /*------------------------------------------------------------------------
  2257. NET_PING: Someone is pinging me to get a response time measure (will only
  2258. happen after I've joined a game). Do nothing; the IPX Manager will handle
  2259. sending an ACK, and updating the response time measurements.
  2260. ------------------------------------------------------------------------*/
  2261. else if (GPacket.Command==NET_PING) {
  2262. retcode = EV_NONE;
  2263. }
  2264. /*------------------------------------------------------------------------
  2265. Default case: nothing happened. (This case will be hit every time I
  2266. receive my own NET_QUERY_GAME or NET_QUERY_PLAYER packets.)
  2267. ------------------------------------------------------------------------*/
  2268. else {
  2269. retcode = EV_NONE;
  2270. }
  2271. return(retcode);
  2272. }
  2273. /***********************************************************************************************
  2274. * Net_New_Dialog -- lets user start a new game *
  2275. * *
  2276. * This dialog shows a list of who's requesting to join this game, and lets *
  2277. * the game initiator selectively approve each user. *
  2278. * *
  2279. * ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ *
  2280. * ³ New Network Game ³ *
  2281. * ³ ³ *
  2282. * ³ Players Scenario ³ *
  2283. * ³ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄ¿ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄ¿ ³ *
  2284. * ³ ³ Boffo ³³ ³ Hell's Kitchen ³³ ³ *
  2285. * ³ ³ Bozo ÃÄ´ ³ Heaven's Gate ÃÄ´ ³ *
  2286. * ³ ³ Bonzo ³ ³ ³ ... ³ ³ ³ *
  2287. * ³ ³ ÃÄ´ ³ ÃÄ´ ³ *
  2288. * ³ ³ ³³ ³ ³³ ³ *
  2289. * ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÙ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÙ ³ *
  2290. * ³ [Reject] Count:--- ## ³ *
  2291. * ³ Level:--- ## ³ *
  2292. * ³ ³ *
  2293. * ³ Credits: _____ ³ *
  2294. * ³ [ Bases ] [ Crates ] ³ *
  2295. * ³ [ Tiberium ] [ AI Players ] ³ *
  2296. * ³ ³ *
  2297. * ³ [OK] [Cancel] ³ *
  2298. * ³ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ *
  2299. * ³ ³ ³ ³ *
  2300. * ³ ³ ³ ³ *
  2301. * ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ³ *
  2302. * ³ [Send Message] ³ *
  2303. * ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ *
  2304. * *
  2305. * INPUT: *
  2306. * none. *
  2307. * *
  2308. * OUTPUT: *
  2309. * true = success, false = cancel *
  2310. * *
  2311. * WARNINGS: *
  2312. * MPlayerName & MPlayerGameName must contain this player's name. *
  2313. * *
  2314. * HISTORY: *
  2315. * 02/14/1995 BR : Created. *
  2316. *=============================================================================================*/
  2317. static int Net_New_Dialog(void)
  2318. {
  2319. /* ###Change collision detected! C:\PROJECTS\CODE\NETDLG.CPP... */
  2320. int factor = (SeenBuff.Get_Width() == 320) ? 1 : 2;
  2321. /*........................................................................
  2322. Dialog & button dimensions
  2323. ........................................................................*/
  2324. //D_DIALOG_W = 281; // dialog width
  2325. int d_dialog_w = 287*factor; // dialog width
  2326. int d_dialog_h = 177*factor; // dialog height
  2327. int d_dialog_x = ((320*factor - d_dialog_w) / 2); // dialog x-coord
  2328. int d_dialog_y = ((200*factor - d_dialog_h) / 2); // centered y-coord
  2329. int d_dialog_cx = d_dialog_x + (d_dialog_w / 2); // center x-coord
  2330. int d_txt6_h = 6*factor+1; // ht of 6-pt text
  2331. int d_margin1 = 5*factor; // margin width/height
  2332. int d_margin2 = 2*factor; // margin width/height
  2333. //d_playerlist_w = 100;
  2334. int d_playerlist_w = 106*factor;
  2335. int d_playerlist_h = 27*factor;
  2336. int d_playerlist_x = d_dialog_x + d_margin1;
  2337. int d_playerlist_y = d_dialog_y + d_margin1 + (d_txt6_h * 3);
  2338. int d_scenariolist_w = 162*factor;
  2339. int d_scenariolist_h = 27*factor;
  2340. int d_scenariolist_x = d_dialog_x + d_dialog_w - d_margin1 - d_scenariolist_w;
  2341. int d_scenariolist_y = d_dialog_y + d_margin1 + (d_txt6_h * 3);
  2342. #if (GERMAN | FRENCH)
  2343. int d_reject_w = 55*factor;
  2344. #else
  2345. int d_reject_w = 45*factor;
  2346. #endif
  2347. int d_reject_h = 9*factor;
  2348. int d_reject_x = d_playerlist_x + (d_playerlist_w / 2) - (d_reject_w / 2);
  2349. int d_reject_y = d_playerlist_y + d_playerlist_h + d_margin2;
  2350. int d_count_w = 25*factor;
  2351. int d_count_h = d_txt6_h;
  2352. int d_count_x = d_scenariolist_x + (d_scenariolist_w / 2);
  2353. int d_count_y = d_scenariolist_y + d_scenariolist_h + d_margin2;
  2354. int d_level_w = 25*factor;
  2355. int d_level_h = d_txt6_h;
  2356. int d_level_x = d_scenariolist_x + (d_scenariolist_w / 2);
  2357. int d_level_y = d_count_y + d_count_h;
  2358. int d_credits_w = ((CREDITSBUF_MAX - 1) * 7*factor) + 4*factor;
  2359. //int d_credits_w = ((CREDITSBUF_MAX - 1) * 6*factor) + 3*factor;
  2360. int d_credits_h = 9*factor;
  2361. int d_credits_x = d_dialog_cx + 2*factor;
  2362. int d_credits_y = d_level_y + d_level_h + d_margin1;
  2363. #if (GERMAN | FRENCH)
  2364. int d_bases_w = 120*factor;//bga:100;
  2365. #else
  2366. int d_bases_w = 100*factor;
  2367. #endif
  2368. int d_bases_h = 9*factor;
  2369. int d_bases_x = d_dialog_cx - d_bases_w - d_margin2;
  2370. int d_bases_y = d_credits_y + d_credits_h + d_margin2;
  2371. #if (GERMAN | FRENCH)
  2372. int d_tiberium_w = 120*factor;
  2373. #else
  2374. int d_tiberium_w = 100*factor;
  2375. #endif
  2376. int d_tiberium_h = 9*factor;
  2377. int d_tiberium_x = d_dialog_cx - d_bases_w - d_margin2;
  2378. int d_tiberium_y = d_bases_y + d_bases_h + d_margin2;
  2379. #if (GERMAN | FRENCH)
  2380. int d_goodies_w = 120*factor;
  2381. #else
  2382. int d_goodies_w = 100*factor;
  2383. #endif
  2384. int d_goodies_h = 9*factor;
  2385. int d_goodies_x = d_dialog_cx + d_margin2;
  2386. int d_goodies_y = d_credits_y + d_credits_h + d_margin2;
  2387. #if (GERMAN | FRENCH)
  2388. int d_ghosts_w = 120*factor;
  2389. #else
  2390. int d_ghosts_w = 100*factor;
  2391. #endif
  2392. int d_ghosts_h = 9*factor;
  2393. int d_ghosts_x = d_dialog_cx + d_margin2;
  2394. int d_ghosts_y = d_goodies_y + d_goodies_h + d_margin2;
  2395. int d_ok_w = 45*factor;
  2396. int d_ok_h = 9*factor;
  2397. int d_ok_x = d_dialog_cx - d_margin2 - (d_bases_w / 2) - (d_ok_w / 2);
  2398. int d_ok_y = d_ghosts_y + d_ghosts_h + d_margin1;
  2399. #if (GERMAN | FRENCH)
  2400. int d_cancel_w = 50*factor;
  2401. #else
  2402. int d_cancel_w = 45*factor;
  2403. #endif
  2404. int d_cancel_h = 9*factor;
  2405. int d_cancel_x = d_dialog_cx + d_margin2 + (d_goodies_w / 2) - (d_cancel_w / 2);
  2406. int d_cancel_y = d_ghosts_y + d_ghosts_h + d_margin1;
  2407. int d_message_w = d_dialog_w - (d_margin1 * 2);
  2408. int d_message_h = 34*factor;
  2409. int d_message_x = d_dialog_x + d_margin1;
  2410. int d_message_y = d_cancel_y + d_cancel_h + d_margin1;
  2411. int d_send_w = 80*factor;
  2412. int d_send_h = 9*factor;
  2413. int d_send_x = d_dialog_cx - (d_send_w / 2);
  2414. int d_send_y = d_message_y + d_message_h + d_margin2;
  2415. /*........................................................................
  2416. Button Enumerations
  2417. ........................................................................*/
  2418. enum {
  2419. BUTTON_PLAYERLIST = 100,
  2420. BUTTON_SCENARIOLIST,
  2421. BUTTON_REJECT,
  2422. BUTTON_COUNT,
  2423. BUTTON_LEVEL,
  2424. BUTTON_CREDITS,
  2425. BUTTON_BASES,
  2426. BUTTON_TIBERIUM,
  2427. BUTTON_GOODIES,
  2428. BUTTON_GHOSTS,
  2429. BUTTON_OK,
  2430. BUTTON_CANCEL,
  2431. BUTTON_SEND,
  2432. };
  2433. /*........................................................................
  2434. Redraw values: in order from "top" to "bottom" layer of the dialog
  2435. ........................................................................*/
  2436. typedef enum {
  2437. REDRAW_NONE = 0,
  2438. REDRAW_UNIT_COUNT,
  2439. REDRAW_MESSAGE,
  2440. REDRAW_BUTTONS,
  2441. REDRAW_BACKGROUND,
  2442. REDRAW_ALL = REDRAW_BACKGROUND
  2443. } RedrawType;
  2444. /*........................................................................
  2445. Dialog variables
  2446. ........................................................................*/
  2447. RedrawType display = REDRAW_ALL; // redraw level
  2448. bool process = true; // process while true
  2449. KeyNumType input;
  2450. char credbuf[CREDITSBUF_MAX]; // for credit edit box
  2451. int old_cred; // old value in credits buffer
  2452. int transmit; // 1 = re-transmit new game options
  2453. long ok_timer = 0; // for timing OK button
  2454. int index; // index for rejecting a player
  2455. int rc;
  2456. int i,j;
  2457. char *item;
  2458. int tabs[] = {77*factor}; // tabs for player list box
  2459. long ping_timer = 0; // for sending Ping packets
  2460. unsigned char tmp_id[MAX_PLAYERS]; // temp storage for sorting player ID's
  2461. int min_index; // for sorting player ID's
  2462. unsigned char min_id; // for sorting player ID's
  2463. unsigned char id; // connection ID
  2464. char txt[80];
  2465. JoinEventType whahoppa; // event generated by received packets
  2466. static int first_time = 1; // 1 = 1st time this dialog is run
  2467. int message_length;
  2468. int sent_so_far;
  2469. unsigned short magic_number;
  2470. unsigned short crc;
  2471. /*........................................................................
  2472. Buttons
  2473. ........................................................................*/
  2474. GadgetClass *commands; // button list
  2475. void const *up_button;
  2476. void const *down_button;
  2477. if (InMainLoop){
  2478. up_button = Hires_Retrieve("BTN-UP.SHP");
  2479. down_button = Hires_Retrieve("BTN-DN.SHP");
  2480. }else{
  2481. up_button = Hires_Retrieve("BTN-UP2.SHP");
  2482. down_button = Hires_Retrieve("BTN-DN2.SHP");
  2483. }
  2484. ColorListClass playerlist(BUTTON_PLAYERLIST,
  2485. d_playerlist_x, d_playerlist_y, d_playerlist_w, d_playerlist_h,
  2486. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  2487. up_button,
  2488. down_button);
  2489. ListClass scenariolist(BUTTON_SCENARIOLIST,
  2490. d_scenariolist_x, d_scenariolist_y, d_scenariolist_w, d_scenariolist_h,
  2491. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  2492. up_button,
  2493. down_button);
  2494. EditClass credit_edt (BUTTON_CREDITS,
  2495. credbuf, CREDITSBUF_MAX,
  2496. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  2497. d_credits_x, d_credits_y, d_credits_w, d_credits_h, EditClass::ALPHANUMERIC);
  2498. TextButtonClass rejectbtn(BUTTON_REJECT, TXT_REJECT,
  2499. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  2500. #if (GERMAN | FRENCH)
  2501. d_reject_x, d_reject_y);
  2502. #else
  2503. d_reject_x, d_reject_y, d_reject_w, d_reject_h);
  2504. #endif
  2505. GaugeClass countgauge (BUTTON_COUNT,
  2506. d_count_x, d_count_y, d_count_w, d_count_h);
  2507. GaugeClass levelgauge (BUTTON_LEVEL,
  2508. d_level_x, d_level_y, d_level_w, d_level_h);
  2509. TextButtonClass basesbtn(BUTTON_BASES, TXT_BASES_OFF,
  2510. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  2511. d_bases_x, d_bases_y, d_bases_w, d_bases_h);
  2512. TextButtonClass tiberiumbtn(BUTTON_TIBERIUM, TXT_TIBERIUM_OFF,
  2513. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  2514. d_tiberium_x, d_tiberium_y, d_tiberium_w, d_tiberium_h);
  2515. TextButtonClass goodiesbtn(BUTTON_GOODIES, TXT_CRATES_OFF,
  2516. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  2517. d_goodies_x, d_goodies_y, d_goodies_w, d_goodies_h);
  2518. TextButtonClass ghostsbtn(BUTTON_GHOSTS, TXT_AI_PLAYERS_OFF,
  2519. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  2520. d_ghosts_x, d_ghosts_y, d_ghosts_w, d_ghosts_h);
  2521. TextButtonClass okbtn(BUTTON_OK, TXT_OK,
  2522. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  2523. d_ok_x, d_ok_y, d_ok_w, d_ok_h);
  2524. TextButtonClass cancelbtn(BUTTON_CANCEL, TXT_CANCEL,
  2525. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  2526. #if (GERMAN | FRENCH)
  2527. d_cancel_x, d_cancel_y);
  2528. #else
  2529. d_cancel_x, d_cancel_y, d_cancel_w, d_cancel_h);
  2530. #endif
  2531. TextButtonClass sendbtn(BUTTON_SEND, TXT_SEND_MESSAGE,
  2532. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  2533. #if (GERMAN | FRENCH)
  2534. d_send_x, d_send_y);
  2535. #else
  2536. d_send_x, d_send_y, d_send_w, d_send_h);
  2537. #endif
  2538. /*
  2539. ------------------------- Build the button list --------------------------
  2540. */
  2541. commands = &playerlist;
  2542. scenariolist.Add_Tail(*commands);
  2543. credit_edt.Add_Tail(*commands);
  2544. rejectbtn.Add_Tail(*commands);
  2545. countgauge.Add_Tail(*commands);
  2546. levelgauge.Add_Tail(*commands);
  2547. basesbtn.Add_Tail(*commands);
  2548. tiberiumbtn.Add_Tail(*commands);
  2549. goodiesbtn.Add_Tail(*commands);
  2550. ghostsbtn.Add_Tail(*commands);
  2551. okbtn.Add_Tail(*commands);
  2552. cancelbtn.Add_Tail(*commands);
  2553. sendbtn.Add_Tail(*commands);
  2554. playerlist.Set_Tabs(tabs);
  2555. /*
  2556. ----------------------------- Various Inits ------------------------------
  2557. */
  2558. /*........................................................................
  2559. Init dialog values, only the first time through
  2560. ........................................................................*/
  2561. if (first_time) {
  2562. MPlayerCredits = 3000; // init credits & credit buffer
  2563. MPlayerBases = 1; // init scenario parameters
  2564. MPlayerTiberium = 0;
  2565. MPlayerGoodies = 0;
  2566. MPlayerGhosts = 0;
  2567. Special.IsCaptureTheFlag = 0;
  2568. MPlayerUnitCount = (MPlayerCountMax[MPlayerBases] + MPlayerCountMin[MPlayerBases]) / 2;
  2569. first_time = 0;
  2570. }
  2571. /*........................................................................
  2572. Init button states
  2573. ........................................................................*/
  2574. if (MPlayerBases) {
  2575. basesbtn.Turn_On();
  2576. basesbtn.Set_Text(TXT_BASES_ON);
  2577. }
  2578. if (MPlayerTiberium) {
  2579. tiberiumbtn.Turn_On();
  2580. tiberiumbtn.Set_Text(TXT_TIBERIUM_ON);
  2581. }
  2582. if (MPlayerGoodies) {
  2583. goodiesbtn.Turn_On();
  2584. goodiesbtn.Set_Text(TXT_CRATES_ON);
  2585. }
  2586. if (MPlayerGhosts) {
  2587. ghostsbtn.Turn_On();
  2588. ghostsbtn.Set_Text(TXT_AI_PLAYERS_ON);
  2589. }
  2590. if (Special.IsCaptureTheFlag) {
  2591. MPlayerGhosts = 0;
  2592. ghostsbtn.Turn_On();
  2593. ghostsbtn.Set_Text(TXT_CAPTURE_THE_FLAG);
  2594. }
  2595. sprintf(credbuf, "%d", MPlayerCredits);
  2596. credit_edt.Set_Text(credbuf, CREDITSBUF_MAX);
  2597. old_cred = MPlayerCredits;
  2598. levelgauge.Set_Maximum(MPLAYER_BUILD_LEVEL_MAX - 1);
  2599. levelgauge.Set_Value(BuildLevel - 1);
  2600. countgauge.Set_Maximum(MPlayerCountMax[MPlayerBases] - MPlayerCountMin[MPlayerBases]);
  2601. countgauge.Set_Value(MPlayerUnitCount - MPlayerCountMin[MPlayerBases]);
  2602. /*........................................................................
  2603. Init other scenario parameters
  2604. ........................................................................*/
  2605. Special.IsTGrowth = MPlayerTiberium;
  2606. Special.IsTSpread = MPlayerTiberium;
  2607. transmit = 0;
  2608. /*........................................................................
  2609. Init scenario description list box
  2610. ........................................................................*/
  2611. for (i = 0; i < MPlayerScenarios.Count(); i++) {
  2612. scenariolist.Add_Item (strupr(MPlayerScenarios[i]));
  2613. }
  2614. ScenarioIdx = 0; // 1st scenario is selected
  2615. /*........................................................................
  2616. Init player color-used flags
  2617. ........................................................................*/
  2618. for (i = 0; i < MAX_MPLAYER_COLORS; i++) {
  2619. ColorUsed[i] = 0; // init all colors to available
  2620. }
  2621. ColorUsed[MPlayerColorIdx] = 1; // set my color to used
  2622. playerlist.Set_Selected_Style(ColorListClass::SELECT_BAR, CC_GREEN_SHADOW);
  2623. /*........................................................................
  2624. Init random-number generator, & create a seed to be used for all random
  2625. numbers from here on out
  2626. ........................................................................*/
  2627. randomize();
  2628. Seed = rand();
  2629. /*........................................................................
  2630. Init the message display system
  2631. ........................................................................*/
  2632. Messages.Init (d_message_x + 2*factor, d_message_y + 2*factor, 4, MAX_MESSAGE_LENGTH,
  2633. d_txt6_h);
  2634. /*------------------------------------------------------------------------
  2635. Add myself to the list. Note that since I'm not in the Players Vector,
  2636. the Vector & listbox are now 1 out of sync.
  2637. ------------------------------------------------------------------------*/
  2638. item = new char [MPLAYER_NAME_MAX + 4];
  2639. if (MPlayerHouse==HOUSE_GOOD) {
  2640. sprintf(item,"%s\t%s",MPlayerName,Text_String(TXT_G_D_I));
  2641. } else {
  2642. sprintf(item,"%s\t%s",MPlayerName,Text_String(TXT_N_O_D));
  2643. }
  2644. playerlist.Add_Item(item, MPlayerTColors[MPlayerColorIdx]);
  2645. Load_Title_Screen("HTITLE.PCX", &HidPage, Palette);
  2646. HidPage.Blit(SeenBuff);
  2647. Set_Palette(Palette);
  2648. while (Get_Mouse_State() > 0) Show_Mouse();
  2649. /*
  2650. ---------------------------- Processing loop -----------------------------
  2651. */
  2652. while (process) {
  2653. /*
  2654. ** If we have just received input focus again after running in the background then
  2655. ** we need to redraw.
  2656. */
  2657. if (AllSurfaces.SurfacesRestored){
  2658. AllSurfaces.SurfacesRestored=FALSE;
  2659. display=REDRAW_ALL;
  2660. }
  2661. #if(SHOW_MONO)
  2662. Ipx.Mono_Debug_Print(-1,0);
  2663. #endif
  2664. /*
  2665. ...................... Refresh display if needed ......................
  2666. */
  2667. if (display == REDRAW_UNIT_COUNT){
  2668. /*
  2669. ** Wipe the background behind the unit count then reprint it
  2670. */
  2671. LogicPage->Fill_Rect(d_count_x + d_count_w + 2*factor,
  2672. d_count_y,
  2673. d_count_x + d_count_w + 2*factor + 20,
  2674. d_count_y + 12,
  2675. 0 );
  2676. sprintf(txt,"%d",MPlayerUnitCount);
  2677. Fancy_Text_Print (txt, d_count_x + d_count_w + 2*factor, d_count_y,
  2678. CC_GREEN, TBLACK,
  2679. TPF_NOSHADOW | TPF_6PT_GRAD | TPF_USE_GRAD_PAL);
  2680. display = REDRAW_NONE;
  2681. }
  2682. if (display) {
  2683. Hide_Mouse();
  2684. /*
  2685. .................. Redraw backgound & dialog box ...................
  2686. */
  2687. if (display >= REDRAW_BACKGROUND) {
  2688. /*
  2689. ** Reload and draw the title page
  2690. */
  2691. Load_Title_Screen("HTITLE.PCX", &HidPage, Palette);
  2692. HidPage.Blit(SeenBuff);
  2693. Set_Palette(Palette);
  2694. Dialog_Box(d_dialog_x, d_dialog_y, d_dialog_w, d_dialog_h);
  2695. /*...............................................................
  2696. Dialog & Field labels
  2697. ...............................................................*/
  2698. Draw_Caption (TXT_NETGAME_SETUP, d_dialog_x, d_dialog_y, d_dialog_w);
  2699. Fancy_Text_Print(TXT_PLAYERS,
  2700. d_playerlist_x + (d_playerlist_w / 2), d_playerlist_y - d_txt6_h,
  2701. CC_GREEN, TBLACK,
  2702. TPF_NOSHADOW | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_CENTER);
  2703. Fancy_Text_Print(TXT_SCENARIOS,
  2704. d_scenariolist_x + (d_scenariolist_w / 2),
  2705. d_scenariolist_y - d_txt6_h,
  2706. CC_GREEN, TBLACK,
  2707. TPF_NOSHADOW | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_CENTER);
  2708. Fancy_Text_Print (TXT_COUNT, d_count_x - 2*factor, d_count_y,
  2709. CC_GREEN, TBLACK,
  2710. TPF_NOSHADOW | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_RIGHT);
  2711. sprintf(txt,"%d",MPlayerUnitCount);
  2712. Fancy_Text_Print (txt, d_count_x + d_count_w + 2*factor, d_count_y,
  2713. CC_GREEN, TBLACK,
  2714. TPF_NOSHADOW | TPF_6PT_GRAD | TPF_USE_GRAD_PAL);
  2715. Fancy_Text_Print (TXT_LEVEL, d_level_x - 2*factor, d_level_y,
  2716. CC_GREEN, TBLACK,
  2717. TPF_NOSHADOW | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_RIGHT);
  2718. if (BuildLevel <= MPLAYER_BUILD_LEVEL_MAX) {
  2719. sprintf(txt,"%d",BuildLevel);
  2720. } else {
  2721. sprintf(txt, "**");
  2722. }
  2723. Fancy_Text_Print (txt, d_level_x + d_level_w + 2*factor, d_level_y,
  2724. CC_GREEN, TBLACK,
  2725. TPF_NOSHADOW | TPF_6PT_GRAD | TPF_USE_GRAD_PAL);
  2726. Fancy_Text_Print (TXT_START_CREDITS_COLON, d_credits_x - 5*factor,
  2727. d_credits_y + 1*factor, CC_GREEN, TBLACK,
  2728. TPF_NOSHADOW | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_RIGHT);
  2729. }
  2730. /*
  2731. .......................... Redraw buttons ..........................
  2732. */
  2733. if (display >= REDRAW_BUTTONS) {
  2734. commands->Draw_All();
  2735. }
  2736. /*..................................................................
  2737. Draw the messages:
  2738. - Erase an old message first
  2739. - If we're in a game, print the game options (if they've been
  2740. received)
  2741. - If we've been rejected from a game, print that message
  2742. ..................................................................*/
  2743. if (display >= REDRAW_MESSAGE) {
  2744. Draw_Box(d_message_x, d_message_y, d_message_w, d_message_h,
  2745. BOXSTYLE_GREEN_BORDER, true);
  2746. Messages.Draw();
  2747. }
  2748. Show_Mouse();
  2749. display = REDRAW_NONE;
  2750. }
  2751. /*
  2752. ........................... Get user input ............................
  2753. */
  2754. input = commands->Input();
  2755. /*
  2756. ---------------------------- Process input ----------------------------
  2757. */
  2758. switch (input) {
  2759. /*------------------------------------------------------------------
  2760. New Scenario selected.
  2761. ------------------------------------------------------------------*/
  2762. case (BUTTON_SCENARIOLIST | KN_BUTTON):
  2763. if (scenariolist.Current_Index() != ScenarioIdx) {
  2764. ScenarioIdx = scenariolist.Current_Index();
  2765. MPlayerCredits = atoi(credbuf);
  2766. transmit = 1;
  2767. }
  2768. break;
  2769. /*------------------------------------------------------------------
  2770. Reject the currently-selected player (don't allow rejecting myself,
  2771. who will be the first entry in the list)
  2772. ------------------------------------------------------------------*/
  2773. case (BUTTON_REJECT | KN_BUTTON):
  2774. index = playerlist.Current_Index();
  2775. if (index == 0) {
  2776. CCMessageBox().Process (TXT_CANT_REJECT_SELF, TXT_OOPS);
  2777. display = REDRAW_ALL;
  2778. break;
  2779. } else {
  2780. if (index < 0 || index >= playerlist.Count()) {
  2781. CCMessageBox().Process (TXT_SELECT_PLAYER_REJECT,TXT_OOPS);
  2782. display = REDRAW_ALL;
  2783. break;
  2784. }
  2785. }
  2786. memset (&GPacket, 0, sizeof(GlobalPacketType));
  2787. GPacket.Command = NET_REJECT_JOIN;
  2788. Ipx.Send_Global_Message (&GPacket, sizeof (GlobalPacketType), 1,
  2789. &(Players[index - 1]->Address));
  2790. break;
  2791. /*------------------------------------------------------------------
  2792. User adjusts max # units
  2793. ------------------------------------------------------------------*/
  2794. case (BUTTON_COUNT | KN_BUTTON):
  2795. MPlayerUnitCount = countgauge.Get_Value() + MPlayerCountMin[MPlayerBases];
  2796. Hide_Mouse();
  2797. LogicPage->Fill_Rect (d_count_x + d_count_w + 2*factor, d_count_y,
  2798. d_count_x + d_count_w + 14*factor, d_count_y + 6*factor, BLACK);
  2799. sprintf(txt,"%d",MPlayerUnitCount);
  2800. Fancy_Text_Print (txt, d_count_x + d_count_w + 2*factor, d_count_y,
  2801. CC_GREEN, TBLACK,
  2802. TPF_NOSHADOW | TPF_6PT_GRAD | TPF_USE_GRAD_PAL);
  2803. Show_Mouse();
  2804. transmit = 1;
  2805. break;
  2806. /*------------------------------------------------------------------
  2807. User adjusts build level
  2808. ------------------------------------------------------------------*/
  2809. case (BUTTON_LEVEL | KN_BUTTON):
  2810. BuildLevel = levelgauge.Get_Value() + 1;
  2811. if (BuildLevel > MPLAYER_BUILD_LEVEL_MAX) // if it's pegged, max it out
  2812. BuildLevel = MPLAYER_BUILD_LEVEL_MAX;
  2813. Hide_Mouse();
  2814. LogicPage->Fill_Rect (d_level_x + d_level_w + 2*factor, d_level_y,
  2815. d_level_x + d_level_w + 14*factor, d_level_y + 6*factor, BLACK);
  2816. if (BuildLevel <= MPLAYER_BUILD_LEVEL_MAX) {
  2817. sprintf(txt,"%d",BuildLevel);
  2818. } else {
  2819. sprintf(txt, "**");
  2820. }
  2821. Fancy_Text_Print (txt, d_level_x + d_level_w + 2*factor, d_level_y,
  2822. CC_GREEN, TBLACK,
  2823. TPF_NOSHADOW | TPF_6PT_GRAD | TPF_USE_GRAD_PAL);
  2824. Show_Mouse();
  2825. transmit = 1;
  2826. break;
  2827. /*------------------------------------------------------------------
  2828. User edits the credits value; retransmit new game options
  2829. ------------------------------------------------------------------*/
  2830. case (BUTTON_CREDITS | KN_BUTTON):
  2831. MPlayerCredits = atoi(credbuf);
  2832. transmit = 1;
  2833. break;
  2834. /*------------------------------------------------------------------
  2835. Toggle bases:
  2836. - Clear scenario list & rebuild it with new names
  2837. - toggle bases button, change its text
  2838. - adjust the MPlayerUnitCount to reflect the new allowed range,
  2839. using the current gauge setting
  2840. - Change the unit count gauge limit & value
  2841. ------------------------------------------------------------------*/
  2842. case (BUTTON_BASES | KN_BUTTON):
  2843. if (MPlayerBases) {
  2844. MPlayerBases = 0;
  2845. basesbtn.Turn_Off();
  2846. basesbtn.Set_Text(TXT_BASES_OFF);
  2847. MPlayerUnitCount = Fixed_To_Cardinal (MPlayerCountMax[0]-MPlayerCountMin[0],
  2848. Cardinal_To_Fixed(MPlayerCountMax[1]-MPlayerCountMin[1],
  2849. MPlayerUnitCount-MPlayerCountMin[1])) + MPlayerCountMin[0];
  2850. } else {
  2851. MPlayerBases = 1;
  2852. basesbtn.Turn_On();
  2853. basesbtn.Set_Text(TXT_BASES_ON);
  2854. MPlayerUnitCount = Fixed_To_Cardinal (MPlayerCountMax[1]-MPlayerCountMin[1],
  2855. Cardinal_To_Fixed(MPlayerCountMax[0]-MPlayerCountMin[0],
  2856. MPlayerUnitCount-MPlayerCountMin[0])) + MPlayerCountMin[1];
  2857. }
  2858. MPlayerCredits = atoi(credbuf);
  2859. countgauge.Set_Maximum(MPlayerCountMax[MPlayerBases] - MPlayerCountMin[MPlayerBases]);
  2860. countgauge.Set_Value(MPlayerUnitCount - MPlayerCountMin[MPlayerBases]);
  2861. transmit = 1;
  2862. countgauge.Flag_To_Redraw();
  2863. display = REDRAW_UNIT_COUNT;
  2864. break;
  2865. /*------------------------------------------------------------------
  2866. Toggle tiberium
  2867. ------------------------------------------------------------------*/
  2868. case (BUTTON_TIBERIUM | KN_BUTTON):
  2869. if (MPlayerTiberium) {
  2870. MPlayerTiberium = 0;
  2871. Special.IsTGrowth = 0;
  2872. Special.IsTSpread = 0;
  2873. tiberiumbtn.Turn_Off();
  2874. tiberiumbtn.Set_Text(TXT_TIBERIUM_OFF);
  2875. } else {
  2876. MPlayerTiberium = 1;
  2877. Special.IsTGrowth = 1;
  2878. Special.IsTSpread = 1;
  2879. tiberiumbtn.Turn_On();
  2880. tiberiumbtn.Set_Text(TXT_TIBERIUM_ON);
  2881. }
  2882. MPlayerCredits = atoi(credbuf);
  2883. transmit = 1;
  2884. break;
  2885. /*------------------------------------------------------------------
  2886. Toggle goodies
  2887. ------------------------------------------------------------------*/
  2888. case (BUTTON_GOODIES | KN_BUTTON):
  2889. if (MPlayerGoodies) {
  2890. MPlayerGoodies = 0;
  2891. goodiesbtn.Turn_Off();
  2892. goodiesbtn.Set_Text(TXT_CRATES_OFF);
  2893. } else {
  2894. MPlayerGoodies = 1;
  2895. goodiesbtn.Turn_On();
  2896. goodiesbtn.Set_Text(TXT_CRATES_ON);
  2897. }
  2898. MPlayerCredits = atoi(credbuf);
  2899. transmit = 1;
  2900. break;
  2901. /*------------------------------------------------------------------
  2902. Toggle ghosts/capture-the-flag
  2903. ------------------------------------------------------------------*/
  2904. case (BUTTON_GHOSTS | KN_BUTTON):
  2905. if (!MPlayerGhosts && !Special.IsCaptureTheFlag) { // ghosts OFF => ghosts ON
  2906. MPlayerGhosts = 1;
  2907. Special.IsCaptureTheFlag = 0;
  2908. ghostsbtn.Turn_On();
  2909. ghostsbtn.Set_Text(TXT_AI_PLAYERS_ON);
  2910. } else {
  2911. if (MPlayerGhosts) { // ghosts ON => capture-flag
  2912. MPlayerGhosts = 0;
  2913. Special.IsCaptureTheFlag = 1;
  2914. ghostsbtn.Turn_On();
  2915. ghostsbtn.Set_Text(TXT_CAPTURE_THE_FLAG);
  2916. } else {
  2917. if (Special.IsCaptureTheFlag) { // capture-flag => AI OFF
  2918. MPlayerGhosts = 0;
  2919. Special.IsCaptureTheFlag = 0;
  2920. ghostsbtn.Turn_Off();
  2921. ghostsbtn.Set_Text(TXT_AI_PLAYERS_OFF);
  2922. }
  2923. }
  2924. }
  2925. MPlayerCredits = atoi(credbuf);
  2926. transmit = 1;
  2927. break;
  2928. /*------------------------------------------------------------------
  2929. OK: exit loop with TRUE status
  2930. ------------------------------------------------------------------*/
  2931. case (BUTTON_OK | KN_BUTTON):
  2932. /*...............................................................
  2933. If a new player has joined in the last second, don't allow
  2934. an OK; force a wait longer than 1 second (to give all players
  2935. a chance to know about this new guy)
  2936. ...............................................................*/
  2937. i = MAX(Ipx.Global_Response_Time() * 2, 60);
  2938. while (TickCount.Time() - ok_timer < i)
  2939. Ipx.Service();
  2940. /*...............................................................
  2941. If there are at least 2 players, go ahead & play; error otherwise
  2942. ...............................................................*/
  2943. if (MPlayerSolo || Players.Count() > 0) {
  2944. rc = TRUE;
  2945. process = FALSE;
  2946. } else {
  2947. CCMessageBox().Process (TXT_ONLY_ONE,TXT_OOPS,NULL);
  2948. display = REDRAW_ALL;
  2949. }
  2950. break;
  2951. /*------------------------------------------------------------------
  2952. CANCEL: send a SIGN_OFF, bail out with error code
  2953. ------------------------------------------------------------------*/
  2954. case (KN_ESC):
  2955. if (Messages.Get_Edit_Buf() != NULL) {
  2956. Messages.Input(input);
  2957. display = REDRAW_MESSAGE;
  2958. break;
  2959. }
  2960. case (BUTTON_CANCEL | KN_BUTTON):
  2961. memset (&GPacket, 0, sizeof(GlobalPacketType));
  2962. GPacket.Command = NET_SIGN_OFF;
  2963. strcpy (GPacket.Name, MPlayerName);
  2964. /*...............................................................
  2965. Broadcast my sign-off over my network
  2966. ...............................................................*/
  2967. Ipx.Send_Global_Message (&GPacket, sizeof (GlobalPacketType),
  2968. 0, NULL);
  2969. Ipx.Send_Global_Message (&GPacket, sizeof (GlobalPacketType),
  2970. 0, NULL);
  2971. while (Ipx.Global_Num_Send() > 0 && Ipx.Service() != 0) ;
  2972. /*...............................................................
  2973. Broadcast my sign-off over a bridged network if there is one
  2974. ...............................................................*/
  2975. if (IsBridge) {
  2976. Ipx.Send_Global_Message (&GPacket, sizeof(GlobalPacketType), 0,
  2977. &BridgeNet);
  2978. Ipx.Send_Global_Message (&GPacket, sizeof(GlobalPacketType), 0,
  2979. &BridgeNet);
  2980. }
  2981. while (Ipx.Global_Num_Send() > 0 && Ipx.Service() != 0) ;
  2982. /*...............................................................
  2983. And now, just be absolutely sure, send my sign-off to each
  2984. player in my game. (If there's a bridge between us, the other
  2985. player will have specified my address, so he can cross the
  2986. bridge; but I may not have specified a bridge address, so the
  2987. only way I have of crossing the bridge is to send a packet
  2988. directly to him.)
  2989. ...............................................................*/
  2990. for (i = 0; i < Players.Count(); i++) {
  2991. Ipx.Send_Global_Message (&GPacket, sizeof(GlobalPacketType), 1,
  2992. &(Players[i]->Address));
  2993. Ipx.Service();
  2994. }
  2995. while (Ipx.Global_Num_Send() > 0 && Ipx.Service() != 0) ;
  2996. MPlayerGameName[0] = 0;
  2997. process = false;
  2998. rc = false;
  2999. break;
  3000. /*------------------------------------------------------------------
  3001. Default: manage the inter-player messages
  3002. ------------------------------------------------------------------*/
  3003. default:
  3004. /*...............................................................
  3005. F4/SEND/'M' = send a message
  3006. ...............................................................*/
  3007. if (Messages.Get_Edit_Buf()==NULL) {
  3008. if (input == KN_M || input==(BUTTON_SEND | KN_BUTTON) ||
  3009. input == KN_F4) {
  3010. memset (txt, 0, 80);
  3011. strcpy(txt,Text_String(TXT_TO_ALL)); // "To All:"
  3012. Messages.Add_Edit (MPlayerTColors[MPlayerColorIdx],
  3013. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_FULLSHADOW, txt, d_message_w-70*factor);
  3014. credit_edt.Clear_Focus();
  3015. credit_edt.Flag_To_Redraw();
  3016. display = REDRAW_MESSAGE;
  3017. break;
  3018. }
  3019. } else {
  3020. /*...............................................................
  3021. If we're already editing a message and the user clicks on
  3022. 'Send', translate our input to a Return so Messages.Input() will
  3023. work properly.
  3024. ...............................................................*/
  3025. if (input==(BUTTON_SEND | KN_BUTTON)) {
  3026. input = KN_RETURN;
  3027. }
  3028. }
  3029. /*...............................................................
  3030. Manage the message system (get rid of old messages)
  3031. ...............................................................*/
  3032. if (Messages.Manage()) {
  3033. display = REDRAW_MESSAGE;
  3034. }
  3035. /*...............................................................
  3036. Re-draw the messages & service keyboard input for any message
  3037. being edited.
  3038. ...............................................................*/
  3039. i = Messages.Input(input);
  3040. /*...............................................................
  3041. If 'Input' returned 1, it means refresh the message display.
  3042. ...............................................................*/
  3043. if (i==1) {
  3044. Messages.Draw();
  3045. }
  3046. /*...............................................................
  3047. If 'Input' returned 2, it means redraw the message display.
  3048. ...............................................................*/
  3049. else if (i==2) {
  3050. display = REDRAW_MESSAGE;
  3051. }
  3052. /*...............................................................
  3053. If 'input' returned 3, it means send the current message.
  3054. ...............................................................*/
  3055. else if (i==3) {
  3056. sent_so_far = 0;
  3057. magic_number = MESSAGE_HEAD_MAGIC_NUMBER;
  3058. message_length = strlen(Messages.Get_Edit_Buf());
  3059. crc = (unsigned short)
  3060. (Calculate_CRC(Messages.Get_Edit_Buf(), message_length) &0xffff);
  3061. while ( sent_so_far < message_length ){
  3062. memset (&GPacket, 0, sizeof(GlobalPacketType));
  3063. GPacket.Command = NET_MESSAGE;
  3064. strcpy (GPacket.Name, MPlayerName);
  3065. memcpy (GPacket.Message.Buf, Messages.Get_Edit_Buf()+sent_so_far, COMPAT_MESSAGE_LENGTH-5);
  3066. *(GPacket.Message.Buf + COMPAT_MESSAGE_LENGTH-5) = 0;
  3067. *((unsigned short*)(GPacket.Message.Buf + COMPAT_MESSAGE_LENGTH-4)) = magic_number;
  3068. *((unsigned short*)(GPacket.Message.Buf + COMPAT_MESSAGE_LENGTH-2)) = crc;
  3069. GPacket.Message.ID = Build_MPlayerID (MPlayerColorIdx, MPlayerHouse);
  3070. GPacket.Message.NameCRC = Compute_Name_CRC(MPlayerGameName);
  3071. /*..................................................................
  3072. Send the message to every player in our player list.
  3073. ..................................................................*/
  3074. for (i = 0; i < Players.Count(); i++) {
  3075. Ipx.Send_Global_Message (&GPacket, sizeof(GlobalPacketType), 1,
  3076. &(Players[i]->Address));
  3077. Ipx.Service();
  3078. }
  3079. /*..................................................................
  3080. Add the message to our own list, since we're not in the player list
  3081. on this dialog.
  3082. ..................................................................*/
  3083. sprintf(txt,Text_String (TXT_FROM), MPlayerName, GPacket.Message.Buf);
  3084. Messages.Add_Message (txt, MPlayerTColors[MPlayerColorIdx],
  3085. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_FULLSHADOW, 1200, magic_number, crc);
  3086. magic_number++;
  3087. sent_so_far += COMPAT_MESSAGE_LENGTH-5;
  3088. }
  3089. display = REDRAW_MESSAGE;
  3090. }
  3091. }
  3092. /*---------------------------------------------------------------------
  3093. Detect editing of the credits buffer, transmit new values to players
  3094. ---------------------------------------------------------------------*/
  3095. if (atoi(credbuf) != old_cred) {
  3096. old_cred = Bound(atoi(credbuf), 0, 9999);
  3097. MPlayerCredits = old_cred;
  3098. transmit = 1;
  3099. sprintf(credbuf, "%d", MPlayerCredits);
  3100. credit_edt.Set_Text(credbuf, CREDITSBUF_MAX);
  3101. }
  3102. /*---------------------------------------------------------------------
  3103. Process incoming packets
  3104. ---------------------------------------------------------------------*/
  3105. whahoppa = Get_NewGame_Responses(&playerlist);
  3106. if (whahoppa == EV_NEW_PLAYER) {
  3107. ok_timer = TickCount.Time();
  3108. transmit = 1;
  3109. } else {
  3110. if (whahoppa == EV_MESSAGE) {
  3111. display = REDRAW_MESSAGE;
  3112. }
  3113. }
  3114. /*---------------------------------------------------------------------
  3115. If our Transmit flag is set, we need to send out a game option packet
  3116. ---------------------------------------------------------------------*/
  3117. if (transmit) {
  3118. for (i = 0; i < Players.Count(); i++) {
  3119. memset (&GPacket, 0, sizeof(GlobalPacketType));
  3120. GPacket.Command = NET_GAME_OPTIONS;
  3121. GPacket.ScenarioInfo.Scenario = MPlayerFilenum[ScenarioIdx];
  3122. GPacket.ScenarioInfo.Credits = MPlayerCredits;
  3123. GPacket.ScenarioInfo.IsBases = MPlayerBases;
  3124. GPacket.ScenarioInfo.IsTiberium = MPlayerTiberium;
  3125. GPacket.ScenarioInfo.IsGoodies = MPlayerGoodies;
  3126. GPacket.ScenarioInfo.IsGhosties = MPlayerGhosts;
  3127. GPacket.ScenarioInfo.BuildLevel = BuildLevel;
  3128. GPacket.ScenarioInfo.UnitCount = MPlayerUnitCount;
  3129. GPacket.ScenarioInfo.Seed = Seed;
  3130. GPacket.ScenarioInfo.Special = Special;
  3131. GPacket.ScenarioInfo.GameSpeed = Options.GameSpeed;
  3132. Ipx.Send_Global_Message (&GPacket, sizeof (GlobalPacketType),
  3133. 1, &(Players[i]->Address) );
  3134. }
  3135. transmit = 0;
  3136. }
  3137. /*---------------------------------------------------------------------
  3138. Ping every player in my game, to force the Global Channel to measure
  3139. the connection response time.
  3140. ---------------------------------------------------------------------*/
  3141. if (TickCount.Time() - ping_timer > 15) {
  3142. memset (&GPacket, 0, sizeof(GlobalPacketType));
  3143. GPacket.Command = NET_PING;
  3144. for (i = 0; i < Players.Count(); i++) {
  3145. Ipx.Send_Global_Message (&GPacket, sizeof (GlobalPacketType),
  3146. 1, &(Players[i]->Address) );
  3147. }
  3148. ping_timer = TickCount.Time();
  3149. }
  3150. /*---------------------------------------------------------------------
  3151. Service the Ipx connections
  3152. ---------------------------------------------------------------------*/
  3153. Ipx.Service();
  3154. /*---------------------------------------------------------------------
  3155. Service the sounds & score; GameActive must be false at this point,
  3156. so Call_Back() doesn't intercept global messages from me!
  3157. ---------------------------------------------------------------------*/
  3158. Call_Back();
  3159. } /* end of while */
  3160. /*------------------------------------------------------------------------
  3161. Establish connections with all other players.
  3162. ------------------------------------------------------------------------*/
  3163. if (rc) {
  3164. /*.....................................................................
  3165. Set the number of players in this game, and my ID
  3166. .....................................................................*/
  3167. MPlayerCount = Players.Count() + 1;
  3168. MPlayerLocalID = Build_MPlayerID (MPlayerColorIdx, MPlayerHouse);
  3169. /*.....................................................................
  3170. Get the scenario filename
  3171. .....................................................................*/
  3172. Scenario = MPlayerFilenum[ScenarioIdx];
  3173. /*.....................................................................
  3174. Compute frame delay value for packet transmissions:
  3175. - Divide global channel's response time by 8 (2 to convert to 1-way
  3176. value, 4 more to convert from ticks to frames)
  3177. .....................................................................*/
  3178. MPlayerMaxAhead = MAX( (Ipx.Global_Response_Time() / 8), 2);
  3179. /*.....................................................................
  3180. Send all players the NET_GO packet. Wait until all ACK's have been
  3181. received.
  3182. .....................................................................*/
  3183. memset (&GPacket, 0, sizeof(GlobalPacketType));
  3184. GPacket.Command = NET_GO;
  3185. GPacket.ResponseTime.OneWay = MPlayerMaxAhead;
  3186. for (i = 0; i < Players.Count(); i++) {
  3187. Ipx.Send_Global_Message (&GPacket, sizeof (GlobalPacketType),
  3188. 1, &(Players[i]->Address) );
  3189. /*..................................................................
  3190. Wait for all the ACK's to come in.
  3191. ..................................................................*/
  3192. while (Ipx.Global_Num_Send() > 0)
  3193. Ipx.Service();
  3194. }
  3195. /*.....................................................................
  3196. Form connections with all other players. Form the IPX Connection ID
  3197. from the player's Color (high byte) and House (low byte). This
  3198. will let us extract any player's color & house at any time.
  3199. Fill in 'tmp_id' while we're doing this.
  3200. .....................................................................*/
  3201. for (i = 0; i < Players.Count(); i++) {
  3202. id = Build_MPlayerID (Players[i]->Player.Color,
  3203. Players[i]->Player.House);
  3204. tmp_id[i] = id;
  3205. Ipx.Create_Connection(id, Players[i]->Name, &(Players[i]->Address) );
  3206. }
  3207. tmp_id[i] = MPlayerLocalID;
  3208. /*.....................................................................
  3209. Store every player's ID in the MPlayerID[] array. This array will
  3210. determine the order of event execution, so the ID's must be stored
  3211. in the same order on all systems.
  3212. .....................................................................*/
  3213. for (i = 0; i < MPlayerCount; i++) {
  3214. min_index = 0;
  3215. min_id = 0xff;
  3216. for (j = 0; j < MPlayerCount; j++) {
  3217. if (tmp_id[j] < min_id) {
  3218. min_id = tmp_id[j];
  3219. min_index = j;
  3220. }
  3221. }
  3222. MPlayerID[i] = tmp_id[min_index];
  3223. tmp_id[min_index] = 0xff;
  3224. }
  3225. /*.....................................................................
  3226. Fill in the array of player names, including my own.
  3227. .....................................................................*/
  3228. for (i = 0; i < MPlayerCount; i++) {
  3229. if (MPlayerID[i] == MPlayerLocalID) {
  3230. strcpy (MPlayerNames[i], MPlayerName);
  3231. } else {
  3232. strcpy (MPlayerNames[i], Ipx.Connection_Name(MPlayerID[i]));
  3233. }
  3234. }
  3235. }
  3236. /*------------------------------------------------------------------------
  3237. Init network timing values, using previous response times as a measure
  3238. of what our retry delta & timeout should be.
  3239. ------------------------------------------------------------------------*/
  3240. Ipx.Set_Timing (Ipx.Global_Response_Time() + 2, -1,
  3241. Ipx.Global_Response_Time() * 4);
  3242. /*------------------------------------------------------------------------
  3243. Clear all lists
  3244. ------------------------------------------------------------------------*/
  3245. while (scenariolist.Count()) {
  3246. scenariolist.Remove_Item(scenariolist.Get_Item(0));
  3247. }
  3248. Clear_Player_List(&playerlist);
  3249. /*------------------------------------------------------------------------
  3250. Restore screen
  3251. ------------------------------------------------------------------------*/
  3252. Hide_Mouse();
  3253. Load_Title_Screen("HTITLE.PCX", &HidPage, Palette);
  3254. HidPage.Blit(SeenBuff);
  3255. Show_Mouse();
  3256. return(rc);
  3257. }
  3258. /***************************************************************************
  3259. * Get_NewGame_Responses -- processes packets for New Game dialog *
  3260. * *
  3261. * This routine can modify the contents of the given list box, as well *
  3262. * as the contents of the Players Vector global. *
  3263. * *
  3264. * INPUT: *
  3265. * playerlist list of players in this game *
  3266. * *
  3267. * OUTPUT: *
  3268. * EV_NONE = nothing happened *
  3269. * EV_NEW_PLAYER = a new player has joined; false otherwise *
  3270. * EV_MESSAGE = a message was received *
  3271. * *
  3272. * WARNINGS: *
  3273. * none. *
  3274. * *
  3275. * HISTORY: *
  3276. * 04/18/1995 BRR : Created. *
  3277. *=========================================================================*/
  3278. static JoinEventType Get_NewGame_Responses(ColorListClass *playerlist)
  3279. {
  3280. int rc;
  3281. char * item; // general-purpose string
  3282. NodeNameType *who; // node to add to Players Vector
  3283. int i;
  3284. int found;
  3285. JoinEventType retval = EV_NONE;
  3286. int resend;
  3287. char txt[80];
  3288. int color;
  3289. unsigned short magic_number;
  3290. unsigned short crc;
  3291. /*------------------------------------------------------------------------
  3292. If there is no incoming packet, just return
  3293. ------------------------------------------------------------------------*/
  3294. rc = Ipx.Get_Global_Message (&GPacket, &GPacketlen, &GAddress, &GProductID);
  3295. if (!rc || GProductID != IPXGlobalConnClass::COMMAND_AND_CONQUER) {
  3296. return(EV_NONE);
  3297. }
  3298. /*------------------------------------------------------------------------
  3299. Try to handle the packet in a standard way
  3300. ------------------------------------------------------------------------*/
  3301. if (Process_Global_Packet(&GPacket,&GAddress) != 0) {
  3302. return(EV_NONE);
  3303. } else
  3304. /*------------------------------------------------------------------------
  3305. NET_QUERY_JOIN:
  3306. ------------------------------------------------------------------------*/
  3307. if (GPacket.Command==NET_QUERY_JOIN) {
  3308. /*.....................................................................
  3309. See if this name is unique:
  3310. - If the name matches, but the address is different, reject this player
  3311. - If the name & address match, this packet must be a re-send of a
  3312. prevous request; in this case, do nothing. The other player must have
  3313. received my CONFIRM_JOIN packet (since it was sent with an ACK
  3314. required), so we can ignore this resend.
  3315. .....................................................................*/
  3316. found = 0;
  3317. resend = 0;
  3318. for (i = 0; i < Players.Count(); i++) {
  3319. if (!strcmp(Players[i]->Name,GPacket.Name)) {
  3320. if (Players[i]->Address != GAddress) {
  3321. found = 1;
  3322. }
  3323. else {
  3324. resend = 1;
  3325. }
  3326. break;
  3327. }
  3328. }
  3329. if (!strcmp (MPlayerName, GPacket.Name)) {
  3330. found = 1;
  3331. }
  3332. /*.....................................................................
  3333. Reject if name is a duplicate, or if there are too many players:
  3334. .....................................................................*/
  3335. if (found || (Players.Count() >= (MPlayerMax - 1) && !resend) ) {
  3336. memset (&GPacket, 0, sizeof(GlobalPacketType));
  3337. GPacket.Command = NET_REJECT_JOIN;
  3338. Ipx.Send_Global_Message (&GPacket, sizeof (GlobalPacketType),
  3339. 1, &GAddress);
  3340. }
  3341. /*.....................................................................
  3342. If this packet is NOT a resend, accept the player. Grant him the
  3343. requested color if possible.
  3344. .....................................................................*/
  3345. else if (!resend) {
  3346. /*..................................................................
  3347. Add node to the Vector list
  3348. ..................................................................*/
  3349. who = new NodeNameType;
  3350. strcpy(who->Name, GPacket.Name);
  3351. who->Address = GAddress;
  3352. who->Player.House = GPacket.PlayerInfo.House;
  3353. Players.Add (who);
  3354. /*..................................................................
  3355. Set player's color; if requested color isn't used, give it to him;
  3356. otherwise, give him the 1st available color. Mark the color we
  3357. give him as used.
  3358. ..................................................................*/
  3359. if (ColorUsed[GPacket.PlayerInfo.Color] == 0) {
  3360. who->Player.Color = GPacket.PlayerInfo.Color;
  3361. } else {
  3362. for (i = 0; i < MAX_MPLAYER_COLORS; i++) {
  3363. if (ColorUsed[i]==0) {
  3364. who->Player.Color = i;
  3365. break;
  3366. }
  3367. }
  3368. }
  3369. ColorUsed[who->Player.Color] = 1;
  3370. /*..................................................................
  3371. Add player name to the list box
  3372. ..................................................................*/
  3373. item = new char [MPLAYER_NAME_MAX + 4];
  3374. if (GPacket.PlayerInfo.House==HOUSE_GOOD) {
  3375. sprintf(item,"%s\t%s",GPacket.Name,Text_String(TXT_G_D_I));
  3376. } else {
  3377. sprintf(item,"%s\t%s",GPacket.Name,Text_String(TXT_N_O_D));
  3378. }
  3379. playerlist->Add_Item (item, MPlayerTColors[who->Player.Color]);
  3380. /*..................................................................
  3381. Send a confirmation packet
  3382. ..................................................................*/
  3383. memset (&GPacket, 0, sizeof(GlobalPacketType));
  3384. GPacket.Command = NET_CONFIRM_JOIN;
  3385. strcpy(GPacket.Name,MPlayerName);
  3386. GPacket.PlayerInfo.House = who->Player.House;
  3387. GPacket.PlayerInfo.Color = who->Player.Color;
  3388. Ipx.Send_Global_Message (&GPacket, sizeof (GlobalPacketType),
  3389. 1, &GAddress);
  3390. retval = EV_NEW_PLAYER;
  3391. }
  3392. }
  3393. /*------------------------------------------------------------------------
  3394. NET_SIGN_OFF: Another system is signing off: search for that system in
  3395. the player list, & remove it if found
  3396. ------------------------------------------------------------------------*/
  3397. else if (GPacket.Command==NET_SIGN_OFF) {
  3398. for (i = 0; i < Players.Count(); i++) {
  3399. /*
  3400. ....................... Name found; remove it ......................
  3401. */
  3402. if (!strcmp (Players[i]->Name, GPacket.Name) &&
  3403. Players[i]->Address==GAddress) {
  3404. /*...............................................................
  3405. Remove from the list box
  3406. ...............................................................*/
  3407. item = (char *)(playerlist->Get_Item(i + 1));
  3408. playerlist->Remove_Item(item);
  3409. playerlist->Flag_To_Redraw();
  3410. delete [] item;
  3411. /*...............................................................
  3412. Mark his color as available
  3413. ...............................................................*/
  3414. ColorUsed[Players[i]->Player.Color] = 0;
  3415. /*...............................................................
  3416. Delete from the Vector list
  3417. ...............................................................*/
  3418. Players.Delete(Players[i]);
  3419. break;
  3420. }
  3421. }
  3422. }
  3423. /*------------------------------------------------------------------------
  3424. NET_MESSAGE: Someone is sending us a message
  3425. ------------------------------------------------------------------------*/
  3426. else if (GPacket.Command==NET_MESSAGE) {
  3427. sprintf(txt,Text_String (TXT_FROM), GPacket.Name, GPacket.Message.Buf);
  3428. magic_number = *((unsigned short*)(GPacket.Message.Buf + COMPAT_MESSAGE_LENGTH-4));
  3429. crc = *((unsigned short*)(GPacket.Message.Buf + COMPAT_MESSAGE_LENGTH-2));
  3430. color = MPlayerID_To_ColorIndex(GPacket.Message.ID);
  3431. Messages.Add_Message (txt, MPlayerTColors[color],
  3432. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_FULLSHADOW, 1200, magic_number, crc);
  3433. retval = EV_MESSAGE;
  3434. }
  3435. return(retval);
  3436. }
  3437. /***************************************************************************
  3438. * Compute_Name_CRC -- computes CRC from char string *
  3439. * *
  3440. * INPUT: *
  3441. * name string to create CRC for *
  3442. * *
  3443. * OUTPUT: *
  3444. * CRC *
  3445. * *
  3446. * WARNINGS: *
  3447. * none. *
  3448. * *
  3449. * HISTORY: *
  3450. * 06/29/1995 BRR : Created. *
  3451. *=========================================================================*/
  3452. unsigned long Compute_Name_CRC(char *name)
  3453. {
  3454. char buf[80];
  3455. unsigned long crc = 0L;
  3456. int i;
  3457. strcpy (buf, name);
  3458. strupr (buf);
  3459. for (i = 0; i < strlen(buf); i++) {
  3460. Add_CRC (&crc, (unsigned long)buf[i]);
  3461. }
  3462. return (crc);
  3463. }
  3464. /***************************************************************************
  3465. * Net_Reconnect_Dialog -- Draws/updates the network reconnect dialog *
  3466. * *
  3467. * INPUT: *
  3468. * reconn 1 = reconnect, 0 = waiting for first-time connection *
  3469. * fresh 1 = draw from scratch, 0 = only update time counter *
  3470. * oldest_index IPX connection index of oldest connection *
  3471. * (only used for reconnection) *
  3472. * timeval value to print in the countdown field *
  3473. * *
  3474. * OUTPUT: *
  3475. * none. *
  3476. * *
  3477. * WARNINGS: *
  3478. * none. *
  3479. * *
  3480. * HISTORY: *
  3481. * 07/08/1995 BRR : Created. *
  3482. *=========================================================================*/
  3483. void Net_Reconnect_Dialog(int reconn, int fresh, int oldest_index,
  3484. unsigned long timeval)
  3485. {
  3486. static int x,y,w,h;
  3487. int id;
  3488. char buf1[40] = {0};
  3489. char buf2[40] = {0};
  3490. char const *buf3 = "";
  3491. int factor = (SeenBuff.Get_Width() == 320) ? 1 : 2;
  3492. int d_txt6_h = 6*factor+1;
  3493. int d_margin = 5*factor;
  3494. /*------------------------------------------------------------------------
  3495. Draw the dialog from scratch
  3496. ------------------------------------------------------------------------*/
  3497. if (fresh) {
  3498. Fancy_Text_Print ("", 0, 0, CC_GREEN, TBLACK,
  3499. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW);
  3500. if (reconn) {
  3501. id = Ipx.Connection_ID(oldest_index);
  3502. sprintf(buf1,Text_String(TXT_RECONNECTING_TO),
  3503. Ipx.Connection_Name(id));
  3504. } else {
  3505. sprintf(buf1,Text_String(TXT_WAITING_FOR_CONNECTIONS));
  3506. }
  3507. sprintf(buf2,Text_String(TXT_TIME_ALLOWED), timeval + 1);
  3508. buf3 = Text_String(TXT_PRESS_ESC);
  3509. w = MAX(String_Pixel_Width(buf1),String_Pixel_Width(buf2));
  3510. w = MAX(String_Pixel_Width(buf3), w);
  3511. w += (d_margin * 2);
  3512. h = (d_txt6_h * 3) + (d_margin * 6);
  3513. x = 160*factor - (w / 2);
  3514. y = 100*factor - (h / 2);
  3515. Hide_Mouse();
  3516. Set_Logic_Page(SeenBuff);
  3517. Dialog_Box(x, y, w, h);
  3518. Fancy_Text_Print (buf1, 160*factor, y + (d_margin * 2), CC_GREEN, BLACK,
  3519. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW);
  3520. Fancy_Text_Print (buf2, 160*factor, y + (d_margin * 2) + d_txt6_h + d_margin,
  3521. CC_GREEN, BLACK,
  3522. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW);
  3523. Fancy_Text_Print (buf3, 160*factor, y + (d_margin * 2) + (d_txt6_h + d_margin) * 2,
  3524. CC_GREEN, BLACK,
  3525. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW);
  3526. Show_Mouse();
  3527. } else {
  3528. /*------------------------------------------------------------------------
  3529. Just update the timeout value on the dialog
  3530. ------------------------------------------------------------------------*/
  3531. Hide_Mouse();
  3532. Set_Logic_Page(SeenBuff);
  3533. sprintf(buf2,Text_String(TXT_TIME_ALLOWED), timeval + 1);
  3534. Fancy_Text_Print (buf2, 160*factor, y + (d_margin * 2) + d_txt6_h + d_margin,
  3535. CC_GREEN, BLACK,
  3536. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW);
  3537. Show_Mouse();
  3538. }
  3539. }
  3540. /***********************************************************************************************
  3541. * Net_Fake_New_Dialog -- Just like Net_New_Dialog but without the Dialog. For internet play *
  3542. * *
  3543. * This 'dialog' does all the non-dialog game set up stuff that is done in the normal *
  3544. * network game set up dialog. The only visible button is 'cancel' *
  3545. * *
  3546. * INPUT: Nothing *
  3547. * *
  3548. * OUTPUT: true if successfully connected *
  3549. * *
  3550. * WARNINGS: None *
  3551. * *
  3552. * HISTORY: *
  3553. * 5/24/96 10:34AM ST : Created *
  3554. *=============================================================================================*/
  3555. static int Net_Fake_New_Dialog(void)
  3556. {
  3557. int factor = (SeenBuff.Get_Width() == 320) ? 1 : 2;
  3558. int d_dialog_w = 120*factor; // dialog width
  3559. int d_dialog_h = 80*factor; // dialog height
  3560. int d_dialog_x = ((320*factor - d_dialog_w) / 2); // dialog x-coord
  3561. int d_dialog_y = ((200*factor - d_dialog_h) / 2); // centered y-coord
  3562. int d_dialog_cx = d_dialog_x + (d_dialog_w / 2); // center x-coord
  3563. //d_playerlist_w = 100;
  3564. int d_playerlist_w = 106*factor;
  3565. int d_playerlist_h = 27*factor;
  3566. int d_playerlist_x = 10 * factor; //off screen
  3567. //int d_playerlist_x = 500*factor; //10 * factor; //off screen
  3568. int d_playerlist_y = d_dialog_y + 20;
  3569. #if (GERMAN | FRENCH)
  3570. int d_cancel_w = 50*factor;
  3571. #else
  3572. int d_cancel_w = 45*factor;
  3573. #endif
  3574. int d_cancel_h = 9*factor;
  3575. int d_cancel_x = d_dialog_cx - (d_cancel_w / 2);
  3576. int d_cancel_y = d_dialog_y + d_dialog_h - 20*factor;
  3577. char text_buffer[64];
  3578. int width;
  3579. int height;
  3580. bool player_joined = false;
  3581. CountDownTimerClass join_timer;
  3582. strcpy(text_buffer, "Connecting....");
  3583. Fancy_Text_Print(TXT_NONE,0,0,TBLACK,TBLACK,TPF_6PT_GRAD | TPF_NOSHADOW);
  3584. Format_Window_String(text_buffer, SeenBuff.Get_Height(), width, height);
  3585. /*........................................................................
  3586. Button Enumerations
  3587. ........................................................................*/
  3588. enum {
  3589. BUTTON_CANCEL = 100,
  3590. BUTTON_PLAYERLIST,
  3591. };
  3592. /*........................................................................
  3593. Redraw values: in order from "top" to "bottom" layer of the dialog
  3594. ........................................................................*/
  3595. typedef enum {
  3596. REDRAW_NONE = 0,
  3597. REDRAW_MESSAGE,
  3598. REDRAW_BUTTONS,
  3599. REDRAW_BACKGROUND,
  3600. REDRAW_ALL = REDRAW_BACKGROUND
  3601. } RedrawType;
  3602. /*........................................................................
  3603. Dialog variables
  3604. ........................................................................*/
  3605. RedrawType display = REDRAW_ALL; // redraw level
  3606. bool process = true; // process while true
  3607. KeyNumType input;
  3608. char credbuf[CREDITSBUF_MAX]; // for credit edit box
  3609. int old_cred; // old value in credits buffer
  3610. int transmit; // 1 = re-transmit new game options
  3611. long ok_timer = 0; // for timing OK button
  3612. int rc;
  3613. int i,j;
  3614. char *item;
  3615. int tabs[] = {77*factor}; // tabs for player list box
  3616. long ping_timer = 0; // for sending Ping packets
  3617. unsigned char tmp_id[MAX_PLAYERS]; // temp storage for sorting player ID's
  3618. int min_index; // for sorting player ID's
  3619. unsigned char min_id; // for sorting player ID's
  3620. unsigned char id; // connection ID
  3621. JoinEventType whahoppa; // event generated by received packets
  3622. void const *up_button;
  3623. void const *down_button;
  3624. if (InMainLoop){
  3625. up_button = Hires_Retrieve("BTN-UP.SHP");
  3626. down_button = Hires_Retrieve("BTN-DN.SHP");
  3627. }else{
  3628. up_button = Hires_Retrieve("BTN-UP2.SHP");
  3629. down_button = Hires_Retrieve("BTN-DN2.SHP");
  3630. }
  3631. /*........................................................................
  3632. Buttons
  3633. ........................................................................*/
  3634. GadgetClass *commands; // button list
  3635. ColorListClass playerlist(BUTTON_PLAYERLIST,
  3636. d_playerlist_x, d_playerlist_y, d_playerlist_w, d_playerlist_h,
  3637. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  3638. up_button,
  3639. down_button);
  3640. TextButtonClass cancelbtn(BUTTON_CANCEL, TXT_CANCEL,
  3641. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  3642. #if (GERMAN | FRENCH)
  3643. d_cancel_x, d_cancel_y);
  3644. #else
  3645. d_cancel_x, d_cancel_y, d_cancel_w, d_cancel_h);
  3646. #endif
  3647. CCDebugString ("C&C95 - In new game dialog - initialising lists.\n");
  3648. /*
  3649. ------------------------- Build the button list --------------------------
  3650. */
  3651. commands = &playerlist;
  3652. cancelbtn.Add_Tail(*commands);
  3653. playerlist.Set_Tabs(tabs);
  3654. /*
  3655. ----------------------------- Various Inits ------------------------------
  3656. */
  3657. sprintf(credbuf, "%d", MPlayerCredits);
  3658. old_cred = MPlayerCredits;
  3659. /*........................................................................
  3660. Init other scenario parameters
  3661. ........................................................................*/
  3662. Special.IsTGrowth = MPlayerTiberium;
  3663. Special.IsTSpread = MPlayerTiberium;
  3664. transmit = 0;
  3665. /*........................................................................
  3666. Init player color-used flags
  3667. ........................................................................*/
  3668. for (i = 0; i < MAX_MPLAYER_COLORS; i++) {
  3669. ColorUsed[i] = 0; // init all colors to available
  3670. }
  3671. ColorUsed[MPlayerColorIdx] = 1; // set my color to used
  3672. playerlist.Set_Selected_Style(ColorListClass::SELECT_BAR, CC_GREEN_SHADOW);
  3673. /*........................................................................
  3674. Init random-number generator, & create a seed to be used for all random
  3675. numbers from here on out
  3676. ........................................................................*/
  3677. randomize();
  3678. Seed = rand();
  3679. /*------------------------------------------------------------------------
  3680. Add myself to the list. Note that since I'm not in the Players Vector,
  3681. the Vector & listbox are now 1 out of sync.
  3682. ------------------------------------------------------------------------*/
  3683. item = new char [MPLAYER_NAME_MAX + 4];
  3684. if (MPlayerHouse==HOUSE_GOOD) {
  3685. sprintf(item,"%s\t%s",MPlayerName,Text_String(TXT_G_D_I));
  3686. } else {
  3687. sprintf(item,"%s\t%s",MPlayerName,Text_String(TXT_N_O_D));
  3688. }
  3689. playerlist.Add_Item(item, MPlayerTColors[MPlayerColorIdx]);
  3690. /*
  3691. ** Process the message loop until we are in focus.
  3692. */
  3693. if (!GameInFocus){
  3694. CCDebugString ("C&C95 - Waiting for game to come into focus.");
  3695. do {
  3696. OutputDebugString (".");
  3697. Keyboard::Check();
  3698. }while (!GameInFocus);
  3699. CCDebugString ("\n");
  3700. AllSurfaces.SurfacesRestored=FALSE;
  3701. }
  3702. CCDebugString ("C&C95 - About to uncompress title page.\n");
  3703. Load_Title_Screen("HTITLE.PCX", &HidPage, Palette);
  3704. HidPage.Blit(SeenBuff);
  3705. CCDebugString ("C&C95 - About to set the palette.\n");
  3706. Set_Palette(Palette);
  3707. CCDebugString ("C&C95 - Palette was set OK.\n");
  3708. if (LogicPage != &SeenBuff && LogicPage!= &HidPage){
  3709. CCDebugString ("C&C95 - Logic page invalid");
  3710. Set_Logic_Page (SeenBuff);
  3711. }
  3712. char a_buffer [128];
  3713. sprintf (a_buffer, "Number of players:%d", Players.Count());
  3714. CCDebugString (a_buffer);
  3715. /*
  3716. ** Send a bogus packet to wake up the VSS
  3717. */
  3718. memset (&GPacket, 0, sizeof(GlobalPacketType));
  3719. GPacket.Command = (NetCommandType)50; //Invalid command
  3720. strcpy (GPacket.Name, MPlayerName);
  3721. Ipx.Send_Global_Message (&GPacket, sizeof (GlobalPacketType), 0, NULL);
  3722. CCDebugString ("C&C95 - About to reveal mouse\n");
  3723. while (Get_Mouse_State() > 0) Show_Mouse();
  3724. /*
  3725. ---------------------------- Processing loop -----------------------------
  3726. */
  3727. CCDebugString ("C&C95 - Entering join dialogue loop\n");
  3728. while (process) {
  3729. /*
  3730. ** If we have just received input focus again after running in the background then
  3731. ** we need to redraw.
  3732. */
  3733. if (AllSurfaces.SurfacesRestored){
  3734. AllSurfaces.SurfacesRestored=FALSE;
  3735. display=REDRAW_ALL;
  3736. }
  3737. /*
  3738. ...................... Refresh display if needed ......................
  3739. */
  3740. if (display) {
  3741. Hide_Mouse();
  3742. /*
  3743. .................. Redraw backgound & dialog box ...................
  3744. */
  3745. if (display >= REDRAW_BACKGROUND) {
  3746. Load_Title_Screen("HTITLE.PCX", &HidPage, Palette);
  3747. HidPage.Blit(SeenBuff);
  3748. Set_Palette(Palette);
  3749. Dialog_Box(d_dialog_x, d_dialog_y, d_dialog_w, d_dialog_h);
  3750. /*...............................................................
  3751. Dialog & Field labels
  3752. ...............................................................*/
  3753. Draw_Caption (TXT_NONE, d_dialog_x, d_dialog_y, d_dialog_w);
  3754. Fancy_Text_Print(text_buffer, d_dialog_cx-width/2, d_dialog_y + 25*factor, CC_GREEN, TBLACK,
  3755. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW);
  3756. }
  3757. /*
  3758. .......................... Redraw buttons ..........................
  3759. */
  3760. if (display >= REDRAW_BUTTONS) {
  3761. commands->Draw_All();
  3762. }
  3763. Show_Mouse();
  3764. display = REDRAW_NONE;
  3765. }
  3766. /*
  3767. ........................... Get user input ............................
  3768. */
  3769. input = commands->Input();
  3770. /*
  3771. ---------------------------- Process input ----------------------------
  3772. */
  3773. switch (input) {
  3774. /*------------------------------------------------------------------
  3775. CANCEL: send a SIGN_OFF, bail out with error code
  3776. ------------------------------------------------------------------*/
  3777. case (KN_ESC):
  3778. case (BUTTON_CANCEL | KN_BUTTON):
  3779. memset (&GPacket, 0, sizeof(GlobalPacketType));
  3780. GPacket.Command = NET_SIGN_OFF;
  3781. strcpy (GPacket.Name, MPlayerName);
  3782. /*...............................................................
  3783. Broadcast my sign-off over my network
  3784. ...............................................................*/
  3785. Ipx.Send_Global_Message (&GPacket, sizeof (GlobalPacketType),
  3786. 0, NULL);
  3787. Ipx.Send_Global_Message (&GPacket, sizeof (GlobalPacketType),
  3788. 0, NULL);
  3789. while (Ipx.Global_Num_Send() > 0 && Ipx.Service() != 0) ;
  3790. /*...............................................................
  3791. Broadcast my sign-off over a bridged network if there is one
  3792. ...............................................................*/
  3793. while (Ipx.Global_Num_Send() > 0 && Ipx.Service() != 0) ;
  3794. /*...............................................................
  3795. And now, just be absolutely sure, send my sign-off to each
  3796. player in my game. (If there's a bridge between us, the other
  3797. player will have specified my address, so he can cross the
  3798. bridge; but I may not have specified a bridge address, so the
  3799. only way I have of crossing the bridge is to send a packet
  3800. directly to him.)
  3801. ...............................................................*/
  3802. for (i = 0; i < Players.Count(); i++) {
  3803. Ipx.Send_Global_Message (&GPacket, sizeof(GlobalPacketType), 1,
  3804. &(Players[i]->Address));
  3805. Ipx.Service();
  3806. }
  3807. while (Ipx.Global_Num_Send() > 0 && Ipx.Service() != 0) ;
  3808. MPlayerGameName[0] = 0;
  3809. process = false;
  3810. rc = false;
  3811. break;
  3812. /*------------------------------------------------------------------
  3813. default: exit loop with TRUE status
  3814. ------------------------------------------------------------------*/
  3815. default:
  3816. char ddkks[128];
  3817. if (Players.Count() == InternetMaxPlayers-1){
  3818. sprintf (ddkks, "C&C95 - Players.Count() = %d\n", Players.Count());
  3819. CCDebugString (ddkks);
  3820. /*
  3821. ** Wait for several secs after receiving request to join before sending
  3822. ** start game packet
  3823. */
  3824. if (!player_joined){
  3825. player_joined = true;
  3826. join_timer.Set (3*60, true);
  3827. break;
  3828. }else{
  3829. if (join_timer.Time()) break;
  3830. }
  3831. CCDebugString ("C&C95 - Join timer expired\n");
  3832. /*...............................................................
  3833. If a new player has joined in the last second, don't allow
  3834. an OK; force a wait longer than 2 seconds (to give all players
  3835. a chance to know about this new guy)
  3836. ...............................................................*/
  3837. i = MAX(Ipx.Global_Response_Time() * 2, 120);
  3838. while (TickCount.Time() - ok_timer < i)
  3839. Ipx.Service();
  3840. /*...............................................................
  3841. If there are at least 2 players, go ahead & play; error otherwise
  3842. ...............................................................*/
  3843. if (MPlayerSolo || Players.Count() > 0) {
  3844. rc = TRUE;
  3845. process = FALSE;
  3846. } else {
  3847. CCMessageBox().Process (TXT_ONLY_ONE,TXT_OOPS,NULL);
  3848. display = REDRAW_ALL;
  3849. }
  3850. }
  3851. break;
  3852. }
  3853. /*---------------------------------------------------------------------
  3854. Process incoming packets
  3855. ---------------------------------------------------------------------*/
  3856. whahoppa = Get_NewGame_Responses(&playerlist);
  3857. if (whahoppa == EV_NEW_PLAYER) {
  3858. ok_timer = TickCount.Time();
  3859. transmit = 1;
  3860. } else {
  3861. if (whahoppa == EV_MESSAGE) {
  3862. display = REDRAW_MESSAGE;
  3863. }
  3864. }
  3865. /*---------------------------------------------------------------------
  3866. If our Transmit flag is set, we need to send out a game option packet
  3867. ---------------------------------------------------------------------*/
  3868. if (transmit) {
  3869. for (i = 0; i < Players.Count(); i++) {
  3870. memset (&GPacket, 0, sizeof(GlobalPacketType));
  3871. GPacket.Command = NET_GAME_OPTIONS;
  3872. GPacket.ScenarioInfo.Scenario = ScenarioIdx; //MPlayerFilenum[ScenarioIdx];
  3873. GPacket.ScenarioInfo.Credits = MPlayerCredits;
  3874. GPacket.ScenarioInfo.IsBases = MPlayerBases;
  3875. GPacket.ScenarioInfo.IsTiberium = MPlayerTiberium;
  3876. GPacket.ScenarioInfo.IsGoodies = MPlayerGoodies;
  3877. GPacket.ScenarioInfo.IsGhosties = MPlayerGhosts;
  3878. GPacket.ScenarioInfo.BuildLevel = BuildLevel;
  3879. GPacket.ScenarioInfo.UnitCount = MPlayerUnitCount;
  3880. GPacket.ScenarioInfo.Seed = Seed;
  3881. GPacket.ScenarioInfo.Special = Special;
  3882. GPacket.ScenarioInfo.GameSpeed = Options.GameSpeed;
  3883. Ipx.Send_Global_Message (&GPacket, sizeof (GlobalPacketType),
  3884. 1, &(Players[i]->Address) );
  3885. }
  3886. transmit = 0;
  3887. }
  3888. /*---------------------------------------------------------------------
  3889. Ping every player in my game, to force the Global Channel to measure
  3890. the connection response time.
  3891. ---------------------------------------------------------------------*/
  3892. if (TickCount.Time() - ping_timer > 15) {
  3893. memset (&GPacket, 0, sizeof(GlobalPacketType));
  3894. GPacket.Command = NET_PING;
  3895. for (i = 0; i < Players.Count(); i++) {
  3896. Ipx.Send_Global_Message (&GPacket, sizeof (GlobalPacketType),
  3897. 1, &(Players[i]->Address) );
  3898. }
  3899. ping_timer = TickCount.Time();
  3900. }
  3901. /*---------------------------------------------------------------------
  3902. Service the Ipx connections
  3903. ---------------------------------------------------------------------*/
  3904. Ipx.Service();
  3905. /*---------------------------------------------------------------------
  3906. Service the sounds & score; GameActive must be false at this point,
  3907. so Call_Back() doesn't intercept global messages from me!
  3908. ---------------------------------------------------------------------*/
  3909. Call_Back();
  3910. } /* end of while */
  3911. CCDebugString ("C&C95 - Exited process loop\n");
  3912. /*------------------------------------------------------------------------
  3913. Establish connections with all other players.
  3914. ------------------------------------------------------------------------*/
  3915. if (rc) {
  3916. /*.....................................................................
  3917. Set the number of players in this game, and my ID
  3918. .....................................................................*/
  3919. MPlayerCount = Players.Count() + 1;
  3920. MPlayerLocalID = Build_MPlayerID (MPlayerColorIdx, MPlayerHouse);
  3921. /*.....................................................................
  3922. Get the scenario filename
  3923. .....................................................................*/
  3924. Scenario = ScenarioIdx; //PlayerFilenum[ScenarioIdx]; We are passed actual number now from wchat not index from
  3925. //Scenario = MPlayerFilenum[ScenarioIdx];
  3926. /*.....................................................................
  3927. Compute frame delay value for packet transmissions:
  3928. - Divide global channel's response time by 8 (2 to convert to 1-way
  3929. value, 4 more to convert from ticks to frames)
  3930. .....................................................................*/
  3931. MPlayerMaxAhead = MAX( (Ipx.Global_Response_Time() / 8), 2);
  3932. /*.....................................................................
  3933. Send all players the NET_GO packet. Wait until all ACK's have been
  3934. received.
  3935. .....................................................................*/
  3936. CCDebugString ("C&C95 - Sending the 'GO' packet\n");
  3937. memset (&GPacket, 0, sizeof(GlobalPacketType));
  3938. GPacket.Command = NET_GO;
  3939. GPacket.ResponseTime.OneWay = MPlayerMaxAhead;
  3940. for (i = 0; i < Players.Count(); i++) {
  3941. char flopbuf [128];
  3942. sprintf (flopbuf, "Sending 'GO' packet to address %d\n", *((unsigned short*)&(Players[i]->Address)));
  3943. CCDebugString (flopbuf);
  3944. Ipx.Send_Global_Message (&GPacket, sizeof (GlobalPacketType),
  3945. 1, &(Players[i]->Address) );
  3946. /*..................................................................
  3947. Wait for all the ACK's to come in.
  3948. ..................................................................*/
  3949. while (Ipx.Global_Num_Send() > 0)
  3950. Ipx.Service();
  3951. }
  3952. /*.....................................................................
  3953. Form connections with all other players. Form the IPX Connection ID
  3954. from the player's Color (high byte) and House (low byte). This
  3955. will let us extract any player's color & house at any time.
  3956. Fill in 'tmp_id' while we're doing this.
  3957. .....................................................................*/
  3958. for (i = 0; i < Players.Count(); i++) {
  3959. id = Build_MPlayerID (Players[i]->Player.Color,
  3960. Players[i]->Player.House);
  3961. tmp_id[i] = id;
  3962. Ipx.Create_Connection(id, Players[i]->Name, &(Players[i]->Address) );
  3963. }
  3964. CCDebugString ("C&C95 - Creating connection to the VSS\n");
  3965. /*
  3966. ** Create an additional connection to the VSS
  3967. */
  3968. if (UseVirtualSubnetServer){
  3969. IPXAddressClass vss_global_address;
  3970. NetNodeType vss_node;
  3971. NetNumType vss_net;
  3972. memset (vss_net, 1, sizeof (vss_net));
  3973. memset (vss_node, 0, sizeof (vss_node));
  3974. vss_global_address.Set_Address(vss_net, vss_node);
  3975. Ipx.Create_Connection( VSS_ID, "VSS", &vss_global_address);
  3976. }
  3977. tmp_id[i] = MPlayerLocalID;
  3978. /*.....................................................................
  3979. Store every player's ID in the MPlayerID[] array. This array will
  3980. determine the order of event execution, so the ID's must be stored
  3981. in the same order on all systems.
  3982. .....................................................................*/
  3983. for (i = 0; i < MPlayerCount; i++) {
  3984. min_index = 0;
  3985. min_id = 0xff;
  3986. for (j = 0; j < MPlayerCount; j++) {
  3987. if (tmp_id[j] < min_id) {
  3988. min_id = tmp_id[j];
  3989. min_index = j;
  3990. }
  3991. }
  3992. MPlayerID[i] = tmp_id[min_index];
  3993. tmp_id[min_index] = 0xff;
  3994. }
  3995. /*.....................................................................
  3996. Fill in the array of player names, including my own.
  3997. .....................................................................*/
  3998. for (i = 0; i < MPlayerCount; i++) {
  3999. if (MPlayerID[i] == MPlayerLocalID) {
  4000. strcpy (MPlayerNames[i], MPlayerName);
  4001. } else {
  4002. strcpy (MPlayerNames[i], Ipx.Connection_Name(MPlayerID[i]));
  4003. }
  4004. }
  4005. }
  4006. /*------------------------------------------------------------------------
  4007. Init network timing values, using previous response times as a measure
  4008. of what our retry delta & timeout should be.
  4009. ------------------------------------------------------------------------*/
  4010. Ipx.Set_Timing (Ipx.Global_Response_Time() + 2, -1,
  4011. Ipx.Global_Response_Time() * 4);
  4012. /*------------------------------------------------------------------------
  4013. Clear all lists
  4014. ------------------------------------------------------------------------*/
  4015. Clear_Player_List(&playerlist);
  4016. /*------------------------------------------------------------------------
  4017. Restore screen
  4018. ------------------------------------------------------------------------*/
  4019. Hide_Mouse();
  4020. Load_Title_Screen("HTITLE.PCX", &HidPage, Palette);
  4021. HidPage.Blit(SeenBuff);
  4022. Show_Mouse();
  4023. return(rc);
  4024. }
  4025. /***********************************************************************************************
  4026. * Net_Fake_Join_Dialog -- Like Net_Join_Dialog but with no dialogs. For Internet Play. *
  4027. * *
  4028. * This 'dialog' does all the non-dialog game set up stuff that is done in the normal *
  4029. * network game set up dialog. The only visible button is 'cancel' *
  4030. * *
  4031. * *
  4032. * INPUT: Nothing *
  4033. * *
  4034. * OUTPUT: 0 = good, -1 = bad *
  4035. * *
  4036. * WARNINGS: None *
  4037. * *
  4038. * HISTORY: *
  4039. * 5/24/96 11:07AM ST : Created *
  4040. *=============================================================================================*/
  4041. static int Net_Fake_Join_Dialog(void)
  4042. {
  4043. int factor = (SeenBuff.Get_Width() == 320) ? 1 : 2;
  4044. /*........................................................................
  4045. Dialog & button dimensions
  4046. ........................................................................*/
  4047. /* ###Change collision detected! C:\PROJECTS\CODE\NETDLG.CPP... */
  4048. int d_dialog_w = 120 *factor; // dialog width
  4049. int d_dialog_h = 80*factor; // dialog height
  4050. int d_dialog_x = ((320*factor - d_dialog_w) / 2); // dialog x-coord
  4051. int d_dialog_y = ((200*factor - d_dialog_h) / 2); // centered y-coord
  4052. int d_dialog_cx = d_dialog_x + (d_dialog_w / 2); // center x-coord
  4053. int d_margin1=10;
  4054. int d_txt6_h=15;
  4055. int d_gamelist_w = 160*factor;
  4056. int d_gamelist_h = 27*factor;
  4057. //int d_gamelist_x = 500*factor; //230*factor; //Off screen
  4058. int d_gamelist_x = 230*factor; //Off screen
  4059. int d_gamelist_y = d_dialog_y + 20;
  4060. int d_playerlist_w = 106*factor;
  4061. int d_playerlist_h = 27*factor;
  4062. int d_playerlist_x = 10 * factor; //Off screen
  4063. //int d_playerlist_x = 500*factor; //10 * factor; //Off screen
  4064. int d_playerlist_y = d_gamelist_y + 20;
  4065. #if (GERMAN | FRENCH)
  4066. int d_cancel_w = 50*factor;
  4067. #else
  4068. int d_cancel_w = 40*factor;
  4069. #endif
  4070. int d_cancel_h = 9*factor;
  4071. int d_cancel_x = d_dialog_cx - d_cancel_w / 2;
  4072. int d_cancel_y = d_dialog_y + d_dialog_h - 20*factor;
  4073. bool ready_to_go = false;
  4074. char text_buffer[64];
  4075. int width;
  4076. int height;
  4077. strcpy(text_buffer, "Connecting....");
  4078. Fancy_Text_Print(TXT_NONE,0,0,TBLACK,TBLACK,TPF_6PT_GRAD | TPF_NOSHADOW);
  4079. Format_Window_String(text_buffer, SeenBuff.Get_Height(), width, height);
  4080. /*........................................................................
  4081. Button Enumerations
  4082. ........................................................................*/
  4083. enum {
  4084. BUTTON_CANCEL = 100,
  4085. BUTTON_GAMELIST,
  4086. BUTTON_PLAYERLIST,
  4087. };
  4088. /*........................................................................
  4089. Redraw values: in order from "top" to "bottom" layer of the dialog
  4090. ........................................................................*/
  4091. typedef enum {
  4092. REDRAW_NONE = 0,
  4093. REDRAW_MESSAGE,
  4094. REDRAW_COLORS,
  4095. REDRAW_BUTTONS,
  4096. REDRAW_BACKGROUND,
  4097. REDRAW_ALL = REDRAW_BACKGROUND
  4098. } RedrawType;
  4099. /*........................................................................
  4100. Dialog variables
  4101. ........................................................................*/
  4102. RedrawType display = REDRAW_ALL; // redraw level
  4103. bool process = true; // process while true
  4104. KeyNumType input;
  4105. JoinStateType joinstate = JOIN_NOTHING; // current "state" of this dialog
  4106. char namebuf[MPLAYER_NAME_MAX] = {0}; // buffer for player's name
  4107. int game_index = -1; // index of currently-selected game
  4108. int join_index = -1; // index of game we're joining
  4109. int rc = 0; // -1 = user cancelled, 1 = New
  4110. JoinEventType event; // event from incoming packet
  4111. int i,j; // loop counter
  4112. int parms_received; // 1 = game options received
  4113. unsigned char tmp_id[MAX_PLAYERS]; // temp storage for sorting player ID's
  4114. int min_index; // for sorting player ID's
  4115. unsigned char min_id; // for sorting player ID's
  4116. unsigned char id; // connection ID
  4117. char * item;
  4118. unsigned long starttime;
  4119. NodeNameType *who;
  4120. void const *up_button;
  4121. void const *down_button;
  4122. if (InMainLoop){
  4123. up_button = Hires_Retrieve("BTN-UP.SHP");
  4124. down_button = Hires_Retrieve("BTN-DN.SHP");
  4125. }else{
  4126. up_button = Hires_Retrieve("BTN-UP2.SHP");
  4127. down_button = Hires_Retrieve("BTN-DN2.SHP");
  4128. }
  4129. /*........................................................................
  4130. Buttons
  4131. ........................................................................*/
  4132. GadgetClass *commands; // button list
  4133. ColorListClass playerlist(BUTTON_PLAYERLIST,
  4134. d_playerlist_x, d_playerlist_y, d_playerlist_w, d_playerlist_h,
  4135. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  4136. up_button,
  4137. down_button);
  4138. ListClass gamelist(BUTTON_GAMELIST,
  4139. d_gamelist_x, d_gamelist_y, d_gamelist_w, d_gamelist_h,
  4140. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  4141. up_button,
  4142. down_button);
  4143. TextButtonClass cancelbtn(BUTTON_CANCEL, TXT_CANCEL,
  4144. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW,
  4145. #if (GERMAN | FRENCH)
  4146. d_cancel_x, d_cancel_y);
  4147. #else
  4148. d_cancel_x, d_cancel_y, d_cancel_w, d_cancel_h);
  4149. #endif
  4150. /*
  4151. ----------------------------- Various Inits ------------------------------
  4152. */
  4153. //MPlayerColorIdx = MPlayerPrefColor; // init my preferred color
  4154. playerlist.Set_Selected_Style(ColorListClass::SELECT_NONE);
  4155. Fancy_Text_Print("", 0, 0, CC_GREEN, TBLACK,
  4156. TPF_CENTER | TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW);
  4157. /*
  4158. --------------------------- Send network query ---------------------------
  4159. */
  4160. CCDebugString ("C&C95 - About to call Send_Join_Queries.\n");
  4161. Send_Join_Queries (game_index, 1, 0);
  4162. /*
  4163. ** Process the message loop until we are in focus.
  4164. */
  4165. if (!GameInFocus){
  4166. CCDebugString ("C&C95 - Waiting for game to come into focus.");
  4167. do {
  4168. CCDebugString (".");
  4169. Keyboard::Check();
  4170. }while (!GameInFocus);
  4171. CCDebugString ("\n");
  4172. AllSurfaces.SurfacesRestored=FALSE;
  4173. }
  4174. CCDebugString ("C&C95 - About to uncompress title page.\n");
  4175. Load_Title_Screen("HTITLE.PCX", &HidPage, Palette);
  4176. HidPage.Blit(SeenBuff);
  4177. CCDebugString ("C&C95 - About to set the palette.\n");
  4178. Set_Palette(Palette);
  4179. CCDebugString ("C&C95 - Palette was set OK.\n");
  4180. if (LogicPage != &SeenBuff && LogicPage!= &HidPage){
  4181. CCDebugString ("C&C95 - Logic page invalid\n");
  4182. Set_Logic_Page (SeenBuff);
  4183. }
  4184. char a_buffer [128];
  4185. sprintf (a_buffer, "C&C95 - Number of players:%d\n", Players.Count());
  4186. CCDebugString (a_buffer);
  4187. /*
  4188. ---------------------------- Init Mono Output ----------------------------
  4189. */
  4190. CCDebugString ("C&C95 - About to reveal mouse\n");
  4191. while (Get_Mouse_State() > 0) Show_Mouse();
  4192. /*
  4193. ---------------------------- Processing loop -----------------------------
  4194. */
  4195. CCDebugString ("C&C95 - Entering join dialogue loop\n");
  4196. while (process) {
  4197. /*
  4198. ** If we have just received input focus again after running in the background then
  4199. ** we need to redraw.
  4200. */
  4201. if (AllSurfaces.SurfacesRestored){
  4202. AllSurfaces.SurfacesRestored=FALSE;
  4203. display=REDRAW_ALL;
  4204. }
  4205. /*
  4206. ...................... Refresh display if needed ......................
  4207. */
  4208. if (display) {
  4209. Hide_Mouse();
  4210. /*
  4211. .................. Redraw backgound & dialog box ...................
  4212. */
  4213. if (display >= REDRAW_BACKGROUND) {
  4214. Load_Title_Screen("HTITLE.PCX", &HidPage, Palette);
  4215. HidPage.Blit(SeenBuff);
  4216. Set_Palette(Palette);
  4217. Dialog_Box(d_dialog_x, d_dialog_y, d_dialog_w, d_dialog_h);
  4218. /*...............................................................
  4219. Dialog & Field labels
  4220. ...............................................................*/
  4221. Draw_Caption (TXT_NONE, d_dialog_x, d_dialog_y, d_dialog_w);
  4222. Fancy_Text_Print(text_buffer, d_dialog_cx-width/2, d_dialog_y + 25*factor, CC_GREEN, TBLACK,
  4223. TPF_6PT_GRAD | TPF_USE_GRAD_PAL | TPF_NOSHADOW);
  4224. /*
  4225. .................... Rebuild the button list ....................
  4226. */
  4227. cancelbtn.Zap();
  4228. gamelist.Zap();
  4229. playerlist.Zap();
  4230. commands = &cancelbtn;
  4231. gamelist.Add_Tail(*commands);
  4232. playerlist.Add_Tail(*commands);
  4233. }
  4234. /*
  4235. .......................... Redraw buttons ..........................
  4236. */
  4237. if (display >= REDRAW_BUTTONS) {
  4238. commands->Draw_All();
  4239. }
  4240. Show_Mouse();
  4241. display = REDRAW_NONE;
  4242. }
  4243. /*
  4244. ........................... Get user input ............................
  4245. */
  4246. input = commands->Input();
  4247. /*
  4248. ---------------------------- Process input ----------------------------
  4249. */
  4250. switch (input) {
  4251. /*------------------------------------------------------------------
  4252. CANCEL: send a SIGN_OFF
  4253. - If we're part of a game, stay in this dialog; otherwise, exit
  4254. ------------------------------------------------------------------*/
  4255. case (KN_ESC):
  4256. case (BUTTON_CANCEL | KN_BUTTON):
  4257. memset (&GPacket, 0, sizeof(GlobalPacketType));
  4258. GPacket.Command = NET_SIGN_OFF;
  4259. strcpy(GPacket.Name,MPlayerName);
  4260. /*...............................................................
  4261. If we're joined to a game, make extra sure the other players in
  4262. that game know I'm exiting; send my SIGN_OFF as an ack-required
  4263. packet. Do not send this packet to myself (index 0).
  4264. ...............................................................*/
  4265. if (joinstate == JOIN_CONFIRMED) {
  4266. //
  4267. // Remove myself from the player list box
  4268. //
  4269. item = (char *)(playerlist.Get_Item(0));
  4270. playerlist.Remove_Item(item);
  4271. delete [] item;
  4272. playerlist.Flag_To_Redraw();
  4273. //
  4274. // Remove myself from the Players list
  4275. //
  4276. who = Players[0];
  4277. Players.Delete(0);
  4278. delete who;
  4279. for (i = 0; i < Players.Count(); i++) {
  4280. Ipx.Send_Global_Message (&GPacket, sizeof(GlobalPacketType), 1,
  4281. &(Players[i]->Address));
  4282. Ipx.Service();
  4283. }
  4284. }
  4285. /*...............................................................
  4286. Now broadcast my SIGN_OFF so other players looking at this game
  4287. know I'm leaving.
  4288. ...............................................................*/
  4289. Ipx.Send_Global_Message (&GPacket, sizeof (GlobalPacketType),
  4290. 0, NULL);
  4291. Ipx.Send_Global_Message (&GPacket, sizeof (GlobalPacketType),
  4292. 0, NULL);
  4293. if (IsBridge) {
  4294. Ipx.Send_Global_Message (&GPacket, sizeof(GlobalPacketType), 0,
  4295. &BridgeNet);
  4296. Ipx.Send_Global_Message (&GPacket, sizeof(GlobalPacketType), 0,
  4297. &BridgeNet);
  4298. }
  4299. while (Ipx.Global_Num_Send() > 0 && Ipx.Service() != 0) ;
  4300. if (joinstate != JOIN_CONFIRMED) {
  4301. process = false;
  4302. rc = -1;
  4303. } else {
  4304. MPlayerGameName[0] = 0;
  4305. joinstate = JOIN_NOTHING;
  4306. display = REDRAW_ALL;
  4307. }
  4308. break;
  4309. /*------------------------------------------------------------------
  4310. JOIN: send a join request packet & switch to waiting-for-confirmation
  4311. mode. (Request_To_Join fills in MPlayerName with my namebuf.)
  4312. ------------------------------------------------------------------*/
  4313. default:
  4314. if (joinstate == JOIN_NOTHING && Games.Count()!=0){
  4315. gamelist.Set_Selected_Index(0);
  4316. join_index = gamelist.Current_Index();
  4317. parms_received = 0;
  4318. if (Request_To_Join (MPlayerName, join_index, &playerlist, MPlayerHouse,
  4319. MPlayerColorIdx)) {
  4320. joinstate = JOIN_WAIT_CONFIRM;
  4321. } else {
  4322. display = REDRAW_ALL;
  4323. }
  4324. }
  4325. break;
  4326. }
  4327. /*---------------------------------------------------------------------
  4328. Resend our query packets
  4329. ---------------------------------------------------------------------*/
  4330. Send_Join_Queries(game_index, 0, 0);
  4331. /*---------------------------------------------------------------------
  4332. Process incoming packets
  4333. ---------------------------------------------------------------------*/
  4334. event = Get_Join_Responses(&joinstate, &gamelist, &playerlist,
  4335. join_index);
  4336. /*.....................................................................
  4337. If we've changed state, redraw everything; if we're starting the game,
  4338. break out of the loop. If we've just joined, send out a player query
  4339. so I'll get added to the list instantly.
  4340. .....................................................................*/
  4341. if (event == EV_STATE_CHANGE) {
  4342. display = REDRAW_ALL;
  4343. if (joinstate==JOIN_GAME_START) {
  4344. CCDebugString ("C&C95 - Received 'GO' packet\n");
  4345. ready_to_go = true;
  4346. } else {
  4347. /*..................................................................
  4348. If we're newly-confirmed, immediately send out a player query
  4349. ..................................................................*/
  4350. if (joinstate==JOIN_CONFIRMED) {
  4351. Clear_Player_List(&playerlist);
  4352. item = new char [MPLAYER_NAME_MAX + 4];
  4353. if (MPlayerHouse==HOUSE_GOOD) {
  4354. sprintf(item,"%s\t%s",MPlayerName,Text_String(TXT_G_D_I));
  4355. } else {
  4356. sprintf(item,"%s\t%s",MPlayerName,Text_String(TXT_N_O_D));
  4357. }
  4358. playerlist.Add_Item (item, MPlayerTColors[MPlayerColorIdx]);
  4359. who = new NodeNameType;
  4360. strcpy(who->Name, MPlayerName);
  4361. who->Address = IPXAddressClass();
  4362. who->Player.House = MPlayerHouse;
  4363. who->Player.Color = MPlayerColorIdx;
  4364. Players.Add (who);
  4365. Send_Join_Queries (game_index, 0, 1);
  4366. } else {
  4367. /*..................................................................
  4368. If we've been rejected, clear any messages we may have been typing.
  4369. ..................................................................*/
  4370. if (joinstate==JOIN_REJECTED) {
  4371. //
  4372. // Remove myself from the player list box
  4373. //
  4374. item = (char *)(playerlist.Get_Item(0));
  4375. if (item){
  4376. playerlist.Remove_Item(item);
  4377. delete [] item;
  4378. playerlist.Flag_To_Redraw();
  4379. }
  4380. //
  4381. // Remove myself from the Players list
  4382. //
  4383. if (Players.Count()){
  4384. who = Players[0];
  4385. Players.Delete(0);
  4386. delete who;
  4387. }
  4388. }
  4389. }
  4390. }
  4391. } else
  4392. /*.....................................................................
  4393. If a new game is detected, and it's the first game on our list,
  4394. automatically send out a player query for that game.
  4395. .....................................................................*/
  4396. if (event == EV_NEW_GAME && gamelist.Count()==1) {
  4397. gamelist.Set_Selected_Index(0);
  4398. game_index = gamelist.Current_Index();
  4399. Send_Join_Queries (game_index, 0, 1);
  4400. } else
  4401. /*.....................................................................
  4402. If the game options have changed, print them.
  4403. .....................................................................*/
  4404. if (event == EV_GAME_OPTIONS) {
  4405. parms_received = 1;
  4406. display = REDRAW_MESSAGE;
  4407. } else
  4408. /*.....................................................................
  4409. Draw an incoming message
  4410. .....................................................................*/
  4411. if (event == EV_MESSAGE) {
  4412. display = REDRAW_MESSAGE;
  4413. } else
  4414. /*.....................................................................
  4415. A game before the one I've selected is gone, so we have a new index now.
  4416. 'game_index' must be kept set to the currently-selected list item, so
  4417. we send out queries for the currently-selected game. It's therefore
  4418. imperative that we detect any changes to the game list.
  4419. If we're joined in a game, we must decrement our game_index to keep
  4420. it aligned with the game we're joined to.
  4421. .....................................................................*/
  4422. if (event == EV_GAME_SIGNOFF) {
  4423. if (joinstate==JOIN_CONFIRMED) {
  4424. game_index--;
  4425. join_index--;
  4426. gamelist.Set_Selected_Index(join_index);
  4427. } else {
  4428. gamelist.Flag_To_Redraw();
  4429. Clear_Player_List(&playerlist);
  4430. game_index = gamelist.Current_Index();
  4431. Send_Join_Queries (game_index, 0, 1);
  4432. }
  4433. }
  4434. /*---------------------------------------------------------------------
  4435. Service the Ipx connections
  4436. ---------------------------------------------------------------------*/
  4437. Ipx.Service();
  4438. /*---------------------------------------------------------------------
  4439. Clean out the Game List; if an old entry is found:
  4440. - Remove it
  4441. - Clear the player list
  4442. - Send queries for the new selected game, if there is one
  4443. ---------------------------------------------------------------------*/
  4444. for (i = 0; i < Games.Count(); i++) {
  4445. if (TickCount.Time() - Games[i]->Game.LastTime > 400) {
  4446. Games.Delete(Games[i]);
  4447. item = (char *)(gamelist.Get_Item (i));
  4448. gamelist.Remove_Item (item);
  4449. delete [] item;
  4450. if (i <= game_index) {
  4451. gamelist.Flag_To_Redraw();
  4452. Clear_Player_List(&playerlist);
  4453. game_index = gamelist.Current_Index();
  4454. Send_Join_Queries (game_index, 0, 1);
  4455. }
  4456. }
  4457. }
  4458. /*
  4459. ** If we were flagged to start the game and we recognise both players then quit the loop
  4460. */
  4461. char ddkks[128];
  4462. sprintf (ddkks, "C&C95 - Players.Count() = %d\n", Players.Count());
  4463. CCDebugString (ddkks);
  4464. if (ready_to_go){ // && Players.Count() == InternetMaxPlayers){
  4465. rc = 0;
  4466. process = false;
  4467. }
  4468. /*---------------------------------------------------------------------
  4469. Service the sounds & score; GameActive must be false at this point,
  4470. so Call_Back() doesn't intercept global messages from me!
  4471. ---------------------------------------------------------------------*/
  4472. Call_Back();
  4473. }
  4474. /*------------------------------------------------------------------------
  4475. Establish connections with all other players.
  4476. ------------------------------------------------------------------------*/
  4477. if (rc == 0) {
  4478. /*.....................................................................
  4479. If the other guys are playing a scenario I don't have (sniff), I can't
  4480. play. Try to bail gracefully.
  4481. .....................................................................*/
  4482. if (ScenarioIdx==-1) {
  4483. CCMessageBox().Process (TXT_UNABLE_PLAY_WAAUGH);
  4484. //
  4485. // Remove myself from the player list box
  4486. //
  4487. item = (char *)(playerlist.Get_Item(0));
  4488. playerlist.Remove_Item(item);
  4489. delete [] item;
  4490. playerlist.Flag_To_Redraw();
  4491. //
  4492. // Remove myself from the Players list
  4493. //
  4494. who = Players[0];
  4495. Players.Delete(0);
  4496. delete who;
  4497. memset (&GPacket, 0, sizeof(GlobalPacketType));
  4498. GPacket.Command = NET_SIGN_OFF;
  4499. strcpy (GPacket.Name, MPlayerName);
  4500. for (i = 0; i < Players.Count(); i++) {
  4501. Ipx.Send_Global_Message (&GPacket, sizeof(GlobalPacketType), 1,
  4502. &(Players[i]->Address));
  4503. Ipx.Service();
  4504. }
  4505. Ipx.Send_Global_Message (&GPacket, sizeof (GlobalPacketType),
  4506. 0, NULL);
  4507. Ipx.Send_Global_Message (&GPacket, sizeof (GlobalPacketType),
  4508. 0, NULL);
  4509. if (IsBridge) {
  4510. Ipx.Send_Global_Message (&GPacket, sizeof(GlobalPacketType), 0,
  4511. &BridgeNet);
  4512. Ipx.Send_Global_Message (&GPacket, sizeof(GlobalPacketType), 0,
  4513. &BridgeNet);
  4514. }
  4515. while (Ipx.Global_Num_Send() > 0 && Ipx.Service() != 0) ;
  4516. rc = -1;
  4517. } else {
  4518. /*..................................................................
  4519. Set the number of players in this game, and my ID
  4520. ..................................................................*/
  4521. MPlayerCount = Players.Count();
  4522. MPlayerLocalID = Build_MPlayerID (MPlayerColorIdx, MPlayerHouse);
  4523. /*..................................................................
  4524. Get the scenario number
  4525. ..................................................................*/
  4526. Scenario = ScenarioIdx; //PlayerFilenum[ScenarioIdx]; We are passed actual number now from wchat not index from
  4527. /*..................................................................
  4528. Form connections with all other players. Form the IPX Connection ID
  4529. from the player's Color and House. This will let us extract any
  4530. player's color & house at any time. Fill in 'tmp_id' while we're
  4531. doing this.
  4532. ..................................................................*/
  4533. for (i = 0; i < Players.Count(); i++) {
  4534. /*...............................................................
  4535. Only create the connection if it's not myself!
  4536. ...............................................................*/
  4537. if (strcmp (MPlayerName, Players[i]->Name)) {
  4538. id = Build_MPlayerID(Players[i]->Player.Color,
  4539. Players[i]->Player.House);
  4540. tmp_id[i] = id;
  4541. Ipx.Create_Connection((int)id, Players[i]->Name, &(Players[i]->Address) );
  4542. } else {
  4543. tmp_id[i] = MPlayerLocalID;
  4544. }
  4545. }
  4546. /*
  4547. ** Create an additional connection to the VSS
  4548. */
  4549. if (UseVirtualSubnetServer){
  4550. IPXAddressClass vss_global_address;
  4551. NetNodeType vss_node;
  4552. NetNumType vss_net;
  4553. memset (vss_net, 1, sizeof (vss_net));
  4554. memset (vss_node, 0, sizeof (vss_node));
  4555. vss_global_address.Set_Address(vss_net, vss_node);
  4556. Ipx.Create_Connection( VSS_ID, "VSS", &vss_global_address);
  4557. }
  4558. /*..................................................................
  4559. Store every player's ID in the MPlayerID[] array. This array will
  4560. determine the order of event execution, so the ID's must be stored
  4561. in the same order on all systems.
  4562. ..................................................................*/
  4563. for (i = 0; i < MPlayerCount; i++) {
  4564. min_index = 0;
  4565. min_id = 0xff;
  4566. for (j = 0; j < MPlayerCount; j++) {
  4567. if (tmp_id[j] < min_id) {
  4568. min_id = tmp_id[j];
  4569. min_index = j;
  4570. }
  4571. }
  4572. MPlayerID[i] = tmp_id[min_index];
  4573. tmp_id[min_index] = 0xff;
  4574. }
  4575. /*..................................................................
  4576. Fill in the array of player names, including my own.
  4577. ..................................................................*/
  4578. for (i = 0; i < MPlayerCount; i++) {
  4579. if (MPlayerID[i] == MPlayerLocalID) {
  4580. strcpy (MPlayerNames[i], MPlayerName);
  4581. } else {
  4582. strcpy (MPlayerNames[i], Ipx.Connection_Name(MPlayerID[i]));
  4583. }
  4584. }
  4585. }
  4586. /*---------------------------------------------------------------------
  4587. Wait a while, polling the IPX service routines, to give our ACK
  4588. a chance to get to the other system. If he doesn't get our ACK, he'll
  4589. be waiting the whole time we load MIX files.
  4590. ---------------------------------------------------------------------*/
  4591. i = MAX(Ipx.Global_Response_Time() * 2, 120);
  4592. starttime = TickCount.Time();
  4593. while (TickCount.Time() - starttime < i) {
  4594. Ipx.Service();
  4595. }
  4596. }
  4597. /*------------------------------------------------------------------------
  4598. Init network timing values, using previous response times as a measure
  4599. of what our retry delta & timeout should be.
  4600. ------------------------------------------------------------------------*/
  4601. Ipx.Set_Timing (Ipx.Global_Response_Time() + 2, -1,
  4602. Ipx.Global_Response_Time() * 4);
  4603. /*------------------------------------------------------------------------
  4604. Clear all lists
  4605. ------------------------------------------------------------------------*/
  4606. Clear_Game_List(&gamelist);
  4607. Clear_Player_List(&playerlist);
  4608. /*------------------------------------------------------------------------
  4609. Restore screen
  4610. ------------------------------------------------------------------------*/
  4611. Hide_Mouse();
  4612. Load_Title_Screen("HTITLE.PCX", &HidPage, Palette);
  4613. HidPage.Blit(SeenBuff);
  4614. Show_Mouse();
  4615. return(rc);
  4616. }
  4617. #endif