[script] n0=; PA-server v0.008 n1=; Released 0 n2=; ID 0 n3=; Please do not edit the three first lines. Those are needed to count build, checking for updates and confirming the script. n4= n5=; TODO n6=; Lage innloggingssystem n7=; Lage sånn at server sender vekk IPene til de som er joina, sånn at nettverket aldri dør ut n8=; Sende info om spillerne(hva da?) (score?) (galaxy?) (ship?) (bygninger?) n9=; Mekke alias $getIP(ID) n10= n11=; v0.008 alias space.replace2 added. Replaces %32 with the space char. The client replaces any spaces in username, password and rulername with %32 before sending it to server. n12=; v0.007 If 16th user is about to be added, the new user will be placed in a new galaxy. Like 2:1 n13=; v0.006 Now saves users with coords in a txtfile called UserGal.txt (rulername 1:1) n14=; v0.005 Updated to this format: "IDxxxx Xxxx client19776 Message/command/request/whatever". clientxx is the name of the socket the reciever should respond to. Easier to make AI bots. n15=; v0.004 Messages are now in this format: "IDxxx Xxxx Message/command/request/whatever" ID is the ID for the client, Xxxx = X is S/C, xxx is numeric n16=; v0.003 Now prefixed numeric with S or C. "C100" means that the message is for a Client, as in "S100" is for a Server n17=; v0.002 Fixed a bug when creating socket. Was creating PA two times n18=; v0.001 Not working n19= n20=on 1:load:{ startPA } n21=on 1:start:{ startPA } n22=on 1:connect:{ startPA } n23= n24=alias startPA { n25= if ($isdir(PA) == $false) { .mkdir $mircdirPA | echo -s $time Folder $micrdirPA has been created } n26= n27= set %PA.ID PA\ID.txt n28= set %PA.password PA\password.txt n29= set %PA.ip PA\ip.txt n30= set %PA.UserGal PA\UserGal.txt n31= n32= if ($exists(%PA.UserGal) == $false) { write -c %PA.UserGal } n33= n34= var %a $openPAsock n35= if (%a == no) { return } n36= n37= echo -s $time Socklisten has been set to %a n38= write -c %PA.ID n39=} n40= n41=alias openPAsock { n42= var %port 9000 n43= if ($portfree(%port) == $true) { socklisten PA %port } n44= else { n45= :loop n46= inc %port n47= if ($portfree(%port) == $true) { if ($sock(PA,1) == PA) { return no } | socklisten PA %port } n48= else goto loop n49= } n50= return %port n51=} n52= n53=alias sc { n54= ; sc stands for sock close n55= n56= write -ds $+ $1 %PA.ID n57= n58= var %users $lines(%PA.ID) n59= echo -s $time (notice) SERVER: $1 has been closed due to $2 secs of idle - Users online: %users n60= n61= sockwrite -tn $1 $1 C900 Your connection has been closed. $2 secs of idletime has been reached. Your ID was $1 Users left behind: %users Your IP was: $3 n62= sockclose $1 n63=} n64= n65=; --------------------------------- ON EVENTS --------------------------------- n66= n67=on 1:socklisten:PA:{ n68= ; Triggers whenever someone want to connect to a port named PA (usually port 9000) n69= n70= var %idletime 999 n71= :new n72= n73= ; Creating a ID - The user has to send the ID for every command n74= var %id ID $+ $rand(1000,9999) n75= var %lines $lines(%PA.ID) n76= n77= if (%lines == 0) { goto ok } n78= n79= ; %id needs to be resolved internally by mIRC by using stupid [ ] n80= var %check $read( %PA.ID , s, [ %id ] ) n81= if (%check) { goto new } n82= n83= :ok n84= sockaccept %id n85= n86= echo -s $str(-,105) n87= echo -s $time (notice) SERVER: Sock accepted... %id n88= n89= write %PA.ID %id n90= n91= sockwrite -tn %id %id C001 Socket Accepted! Your ID is: %id n92= n93= var %v.file $script(pa-server.ini) n94= var %v $read( [ %v.file ] ,l,2) n95= var %v $gettok( [ %v ] ,3,32) n96= n97= sockwrite -tn %id %id C002 I'm running PAserver %v n98= sockwrite -tn %id %id C003 Please log in! Format: "S100 socketname %id username password" n99= n100= sockwrite -tn %id %id C899 Idlelimit is: %idletime n101= n102= .timer $+ %id 1 %idletime { sc %id %idletime $getIP(%id) } n103=} n104= n105=on 1:sockread:*:{ n106= if ($sockerr > 0) { echo -s $time error has occured $1- | return } n107= :loop n108= sockread -fn %temp n109= if ($sockbr == 0) { return } n110= n111= if (%temp) { n112= $servercheck(%temp) n113= $clientcheck(%temp) n114= } n115=} n116= n117=alias servercheck { n118= n119= var %s.txt $gettok($1-,2-,32) n120= var %servercheck $left(%s.txt,1) n121= n122= ; echo -s Servercheck: %servercheck - txt: %s.txt n123= n124= if ($dialog(PAserver)) { did -a PAserver 900 $1- } n125= n126= if (%servercheck == S) { n127= n128= echo -s $time sockread 4SERVER: $1- n129= n130= var %id $gettok($1-,1,32) n131= var %reply.name $gettok($1-,3,32) n132= n133= if ($gettok($1-,2,32) == S100) { n134= n135= var %user $gettok($1-,5,32) n136= if (!%user) { sockwrite -tn %id %id C101 %reply.name Not logged in. The username is missing | halt } n137= n138= var %pass $gettok($1-,6,32) n139= if (!%pass) { sockwrite -tn %id %id C101 %reply.name Not logged in. The password is missing | halt } n140= n141= echo -ts (notice) SERVER: User; %user --- Pass: %pass n142= n143= if ($exists(%PA.password) == $false) { write %PA.password %user %pass } n144= if ($exists(%PA.password) == $true) { n145= var %a $read(%PA.password,s, [ %user ] ) n146= if (%a) { n147= n148= echo -s $time (notice) SERVER: The user ( $+ %user $+ ) has been here before! Saved password: %a ~ Password used now: %pass n149= n150= if (%a === %pass) { n151= sockwrite -tn %id %id C101 %reply.name You have sucessfully logged in n152= sockwrite -tn %id %id C102 %reply.name ID: $space.replace2(%id) - Username: $space.replace2(%user) - Password: $space.replace2(%pass) n153= sockwrite -tn %id %id C103 %reply.name Welcome Back n154= goto IP n155= } | else { n156= sockwrite -tn %id %id C101 %reply.name You have NOT been logged in. n157= sockwrite -tn %id %id C101 %reply.name The password was invalid. Check for spelling errors n158= sockwrite -tn %id %id C101 %reply.name or find yourself a new username. Socket Closed n159= sockclose %id n160= return n161= } n162= } n163= } n164= n165= ; Only if there is a new user n166= n167= write -ds $+ %id %PA.ID n168= write %PA.ID %id %user %pass n169= n170= write %PA.password %user %pass n171= n172= sockwrite -tn %id %id C101 %reply.name Your registration was successful. n173= sockwrite -tn %id %id C102 %reply.name ID: $space.replace2(%id) - Username: $space.replace2(%user) - Password: $space.replace2(%pass) n174= sockwrite -tn %id %id C103 %reply.name You are a new user. Welcome n175= n176= n177= n178= :IP n179= n180= sockwrite -tn %id %id C105 %reply.name IP? Port? n181= } n182= n183= if ($gettok($1-,2,32) == S101) { n184= var %ip $gettok($1-,5,32) n185= var %port $gettok($1-,6,32) n186= write %PA.ip %id %ip %port n187= sockwrite -tn %id %id C106 %reply.name Your IP ( $+ %ip $+ ) and port ( $+ %port $+ ) are saved n188= } n189= if ($gettok($1-,2,32) == S102) { n190= var %ruler $gettok($1-,5,32) n191= set %PAuser %ruler n192= } n193= if ($gettok($1-,2,32) == S103) { n194= var %planet $gettok($1-,5,32) n195= var %a $PAuser( [ %PAuser ] , [ %planet ] ) n196= n197= var %galakse $gettok(%a,1,58) n198= listgalaxy %galakse %id %reply.name n199= n200= echo -st (notice) SERVER: user ( $+ %PAuser $+ ) funnet i %a n201= unset %PAuser n202= } n203= } n204=} n205= n206=; --------------------------------- Aliaser --------------------------------- n207= n208=alias PAuser { n209= if (($1) && ($2)) { n210= n211= ; fikse litt på navna (endre %32 til space) n212= n213= var %32 $chr(37) $+ 32 n214= n215= var %1 $1 n216= if (%32 isin %1) { var %space 1 | var %1 $space.replace2(%1) } n217= n218= var -s %2 $2 n219= if (%32 isin %2) { var %space2 2 | var %2 $space.replace2(%2) } n220= n221= ; Glemte hva jeg skulle sette inn her n222= ; Skulle sette inn if % = 3, da er begge %32 i seg, og må tas hensyn til... n223= n224= n225= var %a $read(%PA.UserGal,sn,$eval($1,2)) n226= var %x $lines(%PA.UserGal) n227= var %z 1 n228= n229= if (%a) { return %a } n230= if (!%a) { n231= echo -ts (notice) SERVER: Ny galakseposisjon lages til ære for %1 n232= n233= inc %x n234= n235= :loop n236= if (%x > 15) { inc %z | dec %x 15 | goto loop } n237= n238= write %PA.UserGal %1 %z $+ : $+ %x %2 n239= return %z $+ : $+ %x n240= } n241= } n242=} n243= n244=alias listgalaxy { n245= n246= var -s %galakse $1 n247= var %id $2 n248= var %reply.name $3 n249= var %file %PA.UserGal n250= n251= if ($exists(%file) == $false) { echo -s The file %file does not exists. Check for errors in alias listgalaxy | halt } n252= var %a 0 n253= n254= :loop n255= inc %a n256= if (%a > 15) { unset %pos | return } n257= n258= var %search %galakse $+ : $+ %a n259= n260= var %readn $calc($readn + 1) n261= var %b $read(%file,w,$eval(* $+ %search $+ *,3), [ %readn ] ) n262= if (!%b) { n263= if (!%pos) { echo -s Variabel pos finnes ikke | halt } n264= did -r PAclient $calc(59 + %pos) n265= did -r PAclient $calc(79 + %pos) n266= n267= ; echo -s Deleting in dialog, ID $calc(59 + %pos) and $calc(79 + %pos) n268= n269= inc %pos n270= n271= goto loop n272= } n273= n274= echo -s variabel b: %b n275= n276= var %ruler $gettok(%b,1,32) n277= set %pos $gettok(%b,2,58) n278= set %pos $gettok(%pos,1,32) n279= var %planet $gettok(%b,3,32) n280= n281= if ($dialog(PAclient)) { n282= did -ra PAclient $calc(59 + %pos) $space.replace2(%ruler) n283= did -ra PAclient $calc(79 + %pos) $space.replace2(%planet) n284= n285= inc %pos n286= echo -s Adding in dialog, ID $calc(59 + %pos) ( $space.replace2(%ruler) ) and $calc(79 + %pos) ( $space.replace2(%planet) ) - pos = %pos n287= n288= } n289= n290= goto loop n291= n292=} n293= n294=alias space.replace2 { n295= if ($1) { n296= return $replace($1,$chr(37) $+ 32,$chr(32)) n297= } n298=} n299= n300=; DIALOG n301= n302=alias openPAserver { n303= if ($dialog(PAserver)) { dialog -v PAserver } | else { dialog -md PAserver PAserver } n304=} n305= n306=dialog PAserver { n307= ; venstre|høyre opp|ned bredde høyde n308= title "Dialog for PA server" n309= size -1 -1 250 200 n310= option dbu n311= n312= tab "Connect",1,3 10 243 185 n313= n314= list 900,5 40 240 155,hsbar,tab 1 n315= n316= button "Reclose",998,193 1 25 10 n317= button "Exit",999,222 1 25 10,ok n318=} n319= n320=menu status,channel { n321= - n322= Open PA Server:openPAserver n323=}