Esempio n. 1
0
 /// <summary>
 /// Send Packet to everyone but sender
 /// </summary>
 public void SendPacket(CString Packet, NCConnection Sender)
 {
     /*
     List<NCConnection> _tmpNCList = new List<NCConnection>();
     foreach (NCConnection nc in NCList)
     {
         _tmpNCList.Add(nc);
     }
     */
     lock (NCList)
     {
         foreach (NCConnection nc in NCList)
         {
             if (nc != Sender)
             {
                 if (nc.Connected)
                 {
                     Console.WriteLine("[NCOUT]: " + Packet.ToString());
                     nc.SendPacket(Packet, true);
                 }
                 //else Console.WriteLine("Failed to send data to NC!");
             }
         }
     }
     //_tmpNCList.Clear ();
     //_tmpNCList = null;
 }
Esempio n. 2
0
        CString toWeaponName(CString code)
        {
            int name_start = code.ToString().IndexOf("toweapons ");
            if (name_start == -1)
                return new CString();
            name_start += 10;	// 10 = strlen("toweapons ")

            int[] name_end = { code.ToString().IndexOf(";", name_start), code.ToString().IndexOf("}", name_start) };
            if (name_end[0] == -1 && name_end[1] == -1)
                return new CString();

            int name_pos = -1;
            if (name_end[0] == -1)
                name_pos = name_end[1];
            if (name_end[1] == -1)
                name_pos = name_end[0];
            if (name_pos == -1)
                name_pos = (name_end[0] < name_end[1]) ? name_end[0] : name_end[1];

            return new CString() + code.ToString().Substring(name_start, name_pos - name_start).Trim();
        }
		/// <summary>
		/// Handle Login Packet
		/// </summary>
		public void SendLogin(string username, string password)
		{
			// Check Type & Version
			int type = 8;
			String version = "NCL21075";
			CString loginPacket = new CString() + (byte)type + version + (byte)username.Length + username + (byte)password.Length + password + "\n";
			SendPacket(loginPacket, true);

			Abstraction.GetInstance().WriteText(loginPacket.ToString());

			this.ReceiveData();

			// Set Login
			LoggedIn = true;
		}
Esempio n. 4
0
        CString setProps(CString pProps, int clientVersion)
        {
            CString ret = new CString();
            int len = 0;
            while (pProps.BytesLeft > 0)
            {
                char propId = pProps.readGUChar();
                CString oldProp = getProp(propId, clientVersion);
                //printf( "propId: %d\n", propId );
                switch ((NPCPROP)propId)
                {
                    case NPCPROP.IMAGE:
                        image = pProps.readChars(pProps.readGUChar());
                        if (image.ToString().Trim().Length != 0)// && clientVersion < CLVER_2_1 && getExtension(image).isEmpty())
                        image += new CString() + ".gif";
                        break;

                    case NPCPROP.SCRIPT:
                        clientScript = pProps.readChars(pProps.readGUShort());
                        break;

                    case NPCPROP.X:
                        if (blockPositionUpdates)
                        {
                            pProps.readGChar();
                            continue;
                        }
                        x = (float)(pProps.readGChar()) / 2.0f;
                        x2 = (int)(x * 16);
                        break;

                    case NPCPROP.Y:
                        if (blockPositionUpdates)
                        {
                            pProps.readGChar();
                            continue;
                        }
                        y = (float)(pProps.readGChar()) / 2.0f;
                        y2 = (int)(y * 16);
                        break;

                    case NPCPROP.POWER:
                        power = pProps.readGUChar();
                        break;

                    case NPCPROP.RUPEES:
                        rupees = (int)pProps.readGUInt();
                        break;

                    case NPCPROP.ARROWS:
                        darts = pProps.readGUChar();
                        break;

                    case NPCPROP.BOMBS:
                        bombs = pProps.readGUChar();
                        break;

                    case NPCPROP.GLOVEPOWER:
                        glovePower = pProps.readGUChar();
                        break;

                    case NPCPROP.BOMBPOWER:
                        bombPower = pProps.readGUChar();
                        break;

                    case NPCPROP.SWORDIMAGE:
                        {
                            int sp = pProps.readGUChar();
                            if (sp <= 4)
                                swordImage = new CString() + "sword" + new CString(sp.ToString()) + ".png";
                            else
                            {
                                sp -= 30;
                                len = pProps.readGUChar();
                                if (len > 0)
                                {
                                    swordImage = pProps.readChars(len);
                                    if (swordImage.ToString().Trim().Length != 0)// && clientVersion < CLVER_2_1 && getExtension(swordImage).isEmpty())
                                    swordImage += new CString() + ".gif";
                                }
                                else
                                    swordImage = new CString() + "";
                                //swordPower = clip(sp, ((settings->getBool("healswords", false) == true) ? -(settings->getInt("swordlimit", 3)) : 0), settings->getInt("swordlimit", 3));
                            }
                            swordPower = (char)sp;
                        }
                        break;

                    case NPCPROP.SHIELDIMAGE:
                        {
                            int sp = pProps.readGUChar();
                            if (sp <= 3)
                                shieldImage = new CString() + "shield" + new CString(sp.ToString()) + ".png";
                            else
                            {
                                sp -= 10;
                                len = pProps.readGUChar();
                                if (len > 0)
                                {
                                    shieldImage = pProps.readChars(len);
                                    if (shieldImage.ToString().Trim().Length != 0)// && clientVersion < CLVER_2_1 && getExtension(shieldImage).isEmpty())
                                    shieldImage += new CString() + ".gif";
                                }
                                else
                                    shieldImage = new CString() + "";
                            }
                            shieldPower = (char)sp;
                        }
                        break;

                    case NPCPROP.GANI:
                    /*
                if (clientVersion < CLVER_2_1)
                {
                    // Older clients don't use ganis.  This is the bow power and image instead.
                    int sp = pProps.readGUChar();
                    if (sp < 10)
                        bowImage = CString() + (char)sp;
                    else
                    {
                        sp -= 10;
                        if (sp < 0) break;
                        bowImage = pProps.readChars(sp);
                        if (!bowImage.isEmpty() && clientVersion < CLVER_2_1 && getExtension(bowImage).isEmpty())
                            bowImage + ".gif";
                        bowImage = CString() + (char)(10 + bowImage.Length) + bowImage;
                    }
                    break;
                }
                    */
                        gani = pProps.readChars(pProps.readGUChar());
                        break;

                    case NPCPROP.VISFLAGS:
                        visFlags = pProps.readGUChar();
                        break;

                    case NPCPROP.BLOCKFLAGS:
                        blockFlags = pProps.readGUChar();
                        break;

                    case NPCPROP.MESSAGE:
                        chatMsg = pProps.readChars(pProps.readGUChar());
                        break;

                    case NPCPROP.HURTDXDY:
                        hurtX = ((float)(pProps.readGUChar() - 32)) / 32;
                        hurtY = ((float)(pProps.readGUChar() - 32)) / 32;
                        break;

                    case NPCPROP.ID:
                        pProps.readGUInt();
                        break;

                    case NPCPROP.SPRITE:
                        sprite = pProps.readGUChar();
                        break;

                    case NPCPROP.COLORS:
                        for (int i = 0; i < 5; i++)
                            colors[i] = pProps.readGUChar();
                        break;

                    case NPCPROP.NICKNAME:
                        nickName = pProps.readChars(pProps.readGUChar());
                        break;

                    case NPCPROP.HORSEIMAGE:
                        horseImage = pProps.readChars(pProps.readGUChar());
                        if (horseImage.ToString().Trim().Length != 0)// && clientVersion < CLVER_2_1 && getExtension(horseImage).isEmpty())
                        horseImage += new CString() + ".gif";
                        break;

                    case NPCPROP.HEADIMAGE:
                        len = pProps.readGUChar();
                        if (len < 100)
                            headImage = new CString() + "head" + new CString(len.ToString()) + ".png";
                        else
                        {
                            headImage = pProps.readChars(len - 100);
                            if (headImage.ToString().Trim().Length != 0)// && clientVersion < CLVER_2_1 && getExtension(headImage).isEmpty())
                            headImage += new CString() + ".gif";
                        }
                        break;

                    case NPCPROP.ALIGNMENT:
                        ap = pProps.readGUChar();
                        if (ap < 0)
                            ap = (char)0;
                        else if (ap > 100)
                            ap = (char)100;
                //ap = clip(ap, 0, 100);
                        break;

                    case NPCPROP.IMAGEPART:
                        imagePart = pProps.readChars(6);
                        break;

                    case NPCPROP.BODYIMAGE:
                        bodyImage = pProps.readChars(pProps.readGUChar());
                        break;

                    case NPCPROP.GMAPLEVELX:
                        gmaplevelx = pProps.readGUChar();
                        break;

                    case NPCPROP.GMAPLEVELY:
                        gmaplevely = pProps.readGUChar();
                        break;

                    case NPCPROP.CLASS:
                        pProps.readChars(pProps.readGShort());
                        break;

                // Location, in pixels, of the npc on the level in 2.3+ clients.
                // Bit 0x0001 controls if it is negative or not.
                // Bits 0xFFFE are the actual value.
                    case NPCPROP.X2:
                        if (blockPositionUpdates)
                        {
                            pProps.readGUShort();
                            continue;
                        }

                        x2 = len = pProps.readGUShort();

                // If the first bit is 1, our position is negative.
                        x2 += 1;
                        if (((short)len & 0x0001) != 0)
                            x2 = -x2;

                // Let pre-2.3+ clients see 2.3+ movement.
                        x = (float)x2 / 16.0f;
                        break;

                    case NPCPROP.Y2:
                        if (blockPositionUpdates)
                        {
                            pProps.readGUShort();
                            continue;
                        }

                        y2 = len = pProps.readGUShort();

                // If the first bit is 1, our position is negative.
                        y2 += 1;
                        if (((short)len & 0x0001) != 0)
                            y2 = -y2;

                // Let pre-2.3+ clients see 2.3+ movement.
                        y = (float)y2 / 16.0f;
                        break;

                    case NPCPROP.SAVE0:
                        saves[0] = pProps.readGUChar();
                        break;
                    case NPCPROP.SAVE1:
                        saves[1] = pProps.readGUChar();
                        break;
                    case NPCPROP.SAVE2:
                        saves[2] = pProps.readGUChar();
                        break;
                    case NPCPROP.SAVE3:
                        saves[3] = pProps.readGUChar();
                        break;
                    case NPCPROP.SAVE4:
                        saves[4] = pProps.readGUChar();
                        break;
                    case NPCPROP.SAVE5:
                        saves[5] = pProps.readGUChar();
                        break;
                    case NPCPROP.SAVE6:
                        saves[6] = pProps.readGUChar();
                        break;
                    case NPCPROP.SAVE7:
                        saves[7] = pProps.readGUChar();
                        break;
                    case NPCPROP.SAVE8:
                        saves[8] = pProps.readGUChar();
                        break;
                    case NPCPROP.SAVE9:
                        saves[9] = pProps.readGUChar();
                        break;

                    case NPCPROP.GATTRIB1:
                        gAttribs[0] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB2:
                        gAttribs[1] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB3:
                        gAttribs[2] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB4:
                        gAttribs[3] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB5:
                        gAttribs[4] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB6:
                        gAttribs[5] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB7:
                        gAttribs[6] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB8:
                        gAttribs[7] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB9:
                        gAttribs[8] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB10:
                        gAttribs[9] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB11:
                        gAttribs[10] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB12:
                        gAttribs[11] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB13:
                        gAttribs[12] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB14:
                        gAttribs[13] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB15:
                        gAttribs[14] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB16:
                        gAttribs[15] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB17:
                        gAttribs[16] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB18:
                        gAttribs[17] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB19:
                        gAttribs[18] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB20:
                        gAttribs[19] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB21:
                        gAttribs[20] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB22:
                        gAttribs[21] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB23:
                        gAttribs[22] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB24:
                        gAttribs[23] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB25:
                        gAttribs[24] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB26:
                        gAttribs[25] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB27:
                        gAttribs[26] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB28:
                        gAttribs[27] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB29:
                        gAttribs[28] = pProps.readChars(pProps.readGUChar());
                        break;
                    case NPCPROP.GATTRIB30:
                        gAttribs[29] = pProps.readChars(pProps.readGUChar());
                        break;

                    default:
                        {
                            Console.Write("NPC %d (%.2f, %.2f): ", id, x, y);
                            Console.Write("Unknown prop: %ud, readPos: %d\n", propId, pProps.ReadCount);
                            for (int i = 0; i < pProps.Length; ++i)
                                Console.Write("%02x ", (char)pProps[i]);
                            Console.Write("\n");
                        }
                        return ret;
                }

                // If a prop changed, adjust its mod time.
                if (propId < (int)NPCPROP.COUNT)
                {
                    if (oldProp != getProp(propId, clientVersion))
                        modTime[propId] = new DateTime();
                }

                // Add to ret.
                ret += new CString() + (char)propId + getProp(propId, clientVersion);
            }
            return ret;
        }
		public void InitNcConnection(CString ncip, CString ncport)
		{
			
			this.form = Abstraction.GetInstance();
			this.serverWindow = ServerWindow.GetInstance();
			
			// Connect to GServer
			
			//NCConn.RunServer();

			//GSConn.Disconnect();
			if (!NCConn.Connected)
			{
				this.form.WriteText("Connecting to NpcServer...");
				this.form.WriteText("Address:\t" + ncip.Text);
				this.form.WriteText("Port:\t\t" + ncport.ToString());
				NCConn.Connect(ncip.Text, ncport.ToInt());

			}
			else
				this.form.WriteText("Already connected!");

			if (NCConn.Connected)
			{
				this.form.WriteText("Connected!");
				NCConn.SendLogin(this.username, this.password);
			}
		}