public BotLogics(PacketHandler ph, PlayerObject[] players, List<Client> clients) { this.ph = ph; this.players = players; local = ph.getLocalPlayer(); this.otherClients = clients; shootTimer = new Timer(100); shootTimer.Elapsed += new ElapsedEventHandler(_shootTimerElapsed); shootTimer.Enabled = true; dropped_items = new List<Item>(); walkingState = WalkingState.EnemySearch; }
public PacketHandler(ConnectionHandler ch, Form1 f, PlayerObject local, PlayerObject[] pl, Client client) { this.packetNumber = 0; this.ch = ch; this.form = f; this.local_player = local; players = pl; known_table = new KnownHandler[255]; cl = client; known_table[1] = handshake; known_table[2] = failed_handshake; known_table[7] = fire; known_table[8] = advancedfire; known_table[9] = weaponchange; known_table[10] = positionUpdate; known_table[11] = positionUpdate; known_table[12] = rotationUpdate; known_table[13] = positionRotationUpdate; known_table[14] = positionRotationUpdate; known_table[15] = setpos; known_table[16] = reload; known_table[17] = hit; known_table[19] = killmsg; known_table[20] = teamchange; known_table[21] = spawnmsg; known_table[22] = roundstart; known_table[23] = weaponbuy; known_table[24] = weapondrop; known_table[25] = weaponpickup; known_table[26] = usepress; known_table[27] = projectile; known_table[28] = spray; known_table[30] = bomb; known_table[32] = specpos; known_table[33] = spawnitem; known_table[41] = unknown1; known_table[43] = vote; known_table[52] = flare; known_table[238] = newname; known_table[240] = chatmsg; known_table[247] = pinglist; known_table[248] = playerjoin; known_table[249] = pingstuff; known_table[252] = joinroutine_known; known_table[253] = playerleave; }
// initializes everything and sends join request to server public Client(IPAddress ipAddress, int port, string name, string password, int usgn_id, string sprayname,Form1 form) { chandler = new ConnectionHandler(ipAddress,port); local_player = new PlayerObject(); players = new PlayerObject[32]; for (int i = 0; i < 32; i++) players[i] = new PlayerObject(); local_player.Name = name; local_player.Password = password; local_player.Usgn = usgn_id; local_player.Spraylogo = sprayname; ph = new PacketHandler(chandler, form, local_player, players,this); bl = new BotLogics(ph, players, form.getClientList()); _logicThread = new Thread(new ThreadStart(bl.Run)); _logicThread.Start(); chandler.AddHandler(ph); ph.AddLogicHandler(bl); chandler.ReceiveMessages(); ph.send_join_confirmation3(); this.form = form; }
private bool canHit(PlayerObject opponent,float distance) { int dx = opponent.X - local.X; int dy = opponent.Y - local.Y; float angle = (float)Math.Atan2(dy, dx); byte[,] tm = ph.getMap.Tilemodemap; if (tm == null) return true; double n_dy = Math.Sin(angle) * collision_resolution; double n_dx = Math.Cos(angle) * collision_resolution; for (int i = 0; i < (int)(Math.Floor(distance) / collision_resolution); i++) { int tx = (int)(local.X + i * n_dx) / 32; int ty = (int)(local.Y + i * n_dy) / 32; if (tx > tm.GetLength(0) || ty > tm.GetLength(1)) return true; if (tm[tx, ty] == 1) // wall return false; } return true; }
public void Run() { int divider = 0; while (true) { System.Threading.Thread.Sleep(20); // 50 fps local = players[ph.getLocalId()]; if (local == null) continue; if (local.Team == 0) // spectator { //continue; int fair_team = selectFairTeam(); ph.send_team_change_20((byte)fair_team, 2); local.Team = (byte)fair_team; } if (local.Health == 0) // dead continue; PlayerObject cl = SelectTarget(true); // hitable target if (cl != null) { float dx = cl.X - local.X; float dy = cl.Y - local.Y; float angle = (float)Math.Atan2(dy, dx) * (float)(180 / Math.PI) + 90.0f; ph.send_rotate_12(angle); if (canShoot) { canShoot = false; local.AmmoIn--; if (local.AmmoIn == 0) { ph.send_reload_16(); b_reloading = true; } //if(!b_reloading) ph.send_fire_7(); } } else { if(b_spin) MakeCircles(); } if (currentRoute != null) // yay a path has been found { //DxMove((currentRoute[0].X * 32+16) - local.X, (currentRoute[0].Y * 32) - local.Y+16); if (currentRoute.Count >= 1) { int targetX = currentRoute[0].X * 32 + 16; int targetY = currentRoute[0].Y * 32 + 16; if (local.X == targetX && local.Y == targetY) { if(currentRoute.Count >= 2) currentRoute.RemoveAt(0); targetX = (currentRoute[0].X * 32 + 16); targetY = (currentRoute[0].Y * 32 + 16); } int next_x = targetX; //.X * 32 + 16; int next_y = targetY; int dx = next_x - local.X; int dy = next_y - local.Y; Vector2D moveVector = new Vector2D(dx, dy); if (moveVector.length() <= walkingSpeed) { DxMove((int)moveVector.X, (int)moveVector.Y); } else { Vector2D moveVectorUniformed = moveVector.Uniform(); DxMove((int)moveVectorUniformed.X * walkingSpeed, (int)moveVectorUniformed.Y * walkingSpeed); } } } /* DETERMINE WALK PATH */ divider++; if (divider == 10) { divider = 0; currentRoute = null; switch (walkingState) { case WalkingState.EnemySearch: PlayerObject cl2 = SelectTarget(false); // walkable target if (cl2 != null) { Goto(cl2.X, cl2.Y); } break; case WalkingState.WeaponSearch: Item scan = ItemScan("primary"); if (scan != null) { Goto(scan.tilex*32 + 16, scan.tiley*32 + 16); } break; case WalkingState.BombPlant: break; } } } }
int playerleave(PacketStream ps) { byte id = ps.ReadByte(); byte reason = ps.ReadByte();// discard reason PlayerObject tmp = players[id]; string textReason; switch (reason) { case 0: textReason = "normal"; break; case 2: textReason = "kicked"; break; case 6: textReason = "banned"; break; case 13: textReason = "voted"; break; case 15: textReason = "speedhacker"; break; default: textReason = "unknown"; break; } LogConsole(String.Format("{0} left the server! reason:{1} {2}", tmp.Name,reason, textReason)); players[id] = new PlayerObject(); // make a new one/overwrite the old one players[id].Id = 0; if (id == own_id) cl.Close(); return 1; }
public void send_join_packet_252_1(PlayerObject p, String ServerKey) { PacketStream ps = new PacketStream(); ps.WriteShort(packetNumber); ps.WriteByte(0xfc); ps.WriteByte(1); ps.WriteString(p.Name); ps.WriteString(p.Password); ps.WriteByte(9); ps.WriteByte(0xc8); ps.WriteByte(0x95); ps.WriteByte(0x9e); ps.WriteByte(0x99); ps.WriteByte(0xaa); ps.WriteByte(0x9b); ps.WriteByte(0xa0); ps.WriteByte(0x9c); ps.WriteByte(0xa4); // dunno what this is ps.WriteShort(0x77); // version ps.WriteInt((uint)p.Usgn); // usgn id ps.WriteString(p.Spraylogo); ps.WriteString(generateAuthCode(ServerKey)); ps.WriteByte(0); ps.WriteString("w028cefe3ac30ab30ab5268978955263db2736128"); ps.WriteByte(0); ch.SendStream(ps,true); }