/// <summary> /// Begins sending server request packet to usgn.de /// </summary> public void GetServers() { IPAddress[] ips = Dns.GetHostAddresses("www.usgn.de"); IPEndPoint ipeUsgn = new IPEndPoint(ips[0], 36963); EndPoint epUsgn = (EndPoint)ipeUsgn; PacketStream ps = new PacketStream(); ps.WriteShort(1); ps.WriteByte(0x14); ps.WriteByte(1); serverlistSocket.BeginSendTo(ps.toArray(), 0, ps.Length, SocketFlags.None, epUsgn, new AsyncCallback(OnSend), null); ReceiveMessages(); }
int failed_handshake(PacketStream ps) { LogConsole("Reliable packet not received by server!"); return 1; }
public void SendStream(PacketStream ps) { clientSocket.BeginSend(ps.toArray(), 0, ps.Length, SocketFlags.None, new AsyncCallback(OnSend), null); if (ps.getType() != 1) ph.PacketNumber++; }
public static PacketStream Copy(PacketStream s) { return (PacketStream)s.MemberwiseClone(); }
/// <summary> /// Function determines what happens when information about a server is returned /// </summary> /// <param name="ps"></param> /// <param name="svi"></param> /// <returns></returns> private int OnServerInformationReceive(PacketStream ps,ServerInformation svi) { byte cmd = ps.ReadByte(); if (cmd == 1) { ps.ReadByte(); // dunno? svi.Name = ps.ReadString(); svi.Map = ps.ReadString(); svi.CurrentClients = ps.ReadByte(); svi.MaxClients = ps.ReadByte(); byte gamemode = ps.ReadByte(); AddServerToGrid(svi); } else if (cmd == 5) { //player info } return 0; }
int roundstart(PacketStream ps) { ps.ReadByte();//unknown int count = ps.ReadByte(); for (int i = 0; i < count; i++) { byte id = ps.ReadByte(); if (id == own_id) botLogics.OnRoundStart(); short sx = ps.ReadShort(); short sy = ps.ReadShort(); float rot = ps.ReadFloat(); byte wpn_id = ps.ReadByte(); /*if (team == 1) team = 2; else if (team == 2) team = 1;*/ byte uk2 = ps.ReadByte(); byte uk3 = ps.ReadByte(); if (id > 0 && id < 33) { PlayerObject tmp = players[id]; tmp.Id = id; //LogConsole(String.Format("mass spawn {0} wpn:{1} uk:{2} uk:{3}", tmp.Name, wpn_id, uk2, uk3)); tmp.X = sx; tmp.Y = sy; tmp.Rotation = rot; tmp.Currentweapon = wpn_id; tmp.Health = 100; } else return 0; } short money = ps.ReadShort(); byte wpnCount = ps.ReadByte(); for (int j = 0; j < wpnCount; j++) { ps.ReadByte(); } return 1; }
int spawnitem(PacketStream ps) { byte wpn_id = ps.ReadByte(); short tilex = ps.ReadShort(); short tiley = ps.ReadShort(); short uk1 = ps.ReadShort(); return 1; }
int killmsg(PacketStream ps) { byte victim = ps.ReadByte(); byte source = ps.ReadByte(); byte wpn_id = ps.ReadByte(); short sx = ps.ReadShort(); short sy = ps.ReadShort(); PlayerObject tmp = players[victim]; tmp.Health = 0; if (victim == own_id) botLogics.OnDeath(); if (source == own_id) botLogics.OnKill(victim); return 1; }
int newname(PacketStream ps) { byte id = ps.ReadByte(); string new_name = ps.ReadString(); players[id].Name = new_name; return 1; }
int hit(PacketStream ps) { byte victim_id = ps.ReadByte(); byte source_id = ps.ReadByte(); byte health = ps.ReadByte(); byte uk0 = ps.ReadByte(); PlayerObject tmp = players[victim_id]; tmp.Health = health; return 1; }
int joinroutine_known(PacketStream ps) { int type2 = ps.ReadByte(); if (type2 == 0) { String serverKey = ps.ReadString(); send_join_packet_252_1(local_player, serverKey); } else if (type2 == 2) { byte state = ps.ReadByte(); if (state == 0) { own_id = ps.ReadByte(); String mapName = ps.ReadString(); String skey = ps.ReadString(); send_map_confirmation(mapName, skey); } else { if (state == 1) LogConsole("Error: wrong password!"); else if (state == 3) LogConsole("Error: server is full!"); else if (state == 4) LogConsole("Error: banned!"); else if (state == 23) LogConsole("Error: maximum number of clients reached!"); else if (state == 22) LogConsole("Error: invalid precon send to server!"); else LogConsole("Error on joining: " + state); cl.Close(); } } else if (type2 == 3) { } else if (type2 == 4) { ps.ReadByte(); send_map_name_252_05(); } else if (type2 == 6) { ps.SkipAll();//server data } else if (type2 == 7) { //Player data int type3 = ps.ReadByte(); if (type3 == 1) { int onlinePlayer = ps.ReadByte(); for (int i = 0; i < onlinePlayer; i++) { PlayerObject temp; byte id = ps.ReadByte(); temp = players[id]; temp.Id = id; temp.Name = StringHelper.DecodePlayerName(ps.ReadString()); string lulz = StringHelper.DecodePlayerName(ps.ReadString()); lulz += 'a'; //ps.ReadByte();//uk temp.Team = ps.ReadByte(); ps.ReadByte(); ps.ReadByte(); //uks temp.Score = ps.ReadShort(); temp.Death = ps.ReadShort(); temp.X = ps.ReadShort(); ps.ReadShort();//uk tile_x temp.Y = ps.ReadShort(); ps.ReadShort(); // uk tile_y? ps.ReadShort();// rotation?? temp.Health = ps.ReadByte(); temp.Armor = ps.ReadByte(); ps.ReadByte();//uk temp.Currentweapon = ps.ReadByte(); ps.ReadByte(); players[temp.Id] = temp; } LogConsole("Own player: " + players[own_id].ToString()); } else if (type3 == 2) { //hostage data ps.SkipAll(); } else if (type3 == 3) { // item data //ps.SkipAll(); int count = ps.ReadByte(); for (int i = 0; i < count; i++) { ps.ReadByte(); ps.ReadByte(); byte wpn_id = ps.ReadByte(); short tilex = ps.ReadShort(); short tiley = ps.ReadShort(); short ammoin = ps.ReadShort(); short ammo = ps.ReadShort(); botLogics.OnWeaponDrop(wpn_id, tilex, tiley, ammo, ammoin); } } else if (type3 == 4) //entity data { ps.SkipAll(); } else if (type3 == 5) //DynamicObjectData { ps.SkipAll(); } else if (type3 == 6) // ProjectileData { ps.SkipAll(); } else if (type3 == 7) //DynamicObjectImageData { ps.SkipAll(); } else if (type3 == 8) { ps.SkipAll(); } else if (type3 == 200) // final ack { LogConsole("Connected!"); ps.ReadString(); ps.ReadByte(); ps.ReadByte(); ps.ReadByte(); send_unknown_packet_28(); //send_spec_pos_32(440, 660); } } else if (type2 == 50) // okay wtf? ps.SkipAll(); return 1; }
int handshake(PacketStream ps) { short packetNumConfirmed = ps.ReadShort(); return 1; // need to check return value }
int flare(PacketStream ps) { ps.Skip(12); return 1; }
int fire(PacketStream ps) { byte id = ps.ReadByte(); if (id == own_id) { botLogics.OnFire(); } return 1; }
int reload(PacketStream ps) { byte id = ps.ReadByte(); byte status = ps.ReadByte(); if (status != 1 && id == own_id) botLogics.OnReloadFinish(); return 1; }
int pinglist(PacketStream ps) { byte count = ps.ReadByte(); for (int i = 0; i < count; i++) { byte id = ps.ReadByte(); ushort ping = (ushort)ps.ReadShort(); } return 1; }
int rotationUpdate(PacketStream ps) { byte id = ps.ReadByte(); float rotation = ps.ReadFloat(); players[id].Rotation = rotation; return 1; }
int pingstuff(PacketStream ps) { uint value = (uint)ps.ReadInt(); send_ping_249(value); return 1; }
int setpos(PacketStream ps) { byte id = ps.ReadByte(); short x = ps.ReadShort(); short y = ps.ReadShort(); players[id].X = x; players[id].Y = y; return 1; }
int playerjoin(PacketStream ps) { byte id = ps.ReadByte(); PlayerObject temp = players[id]; temp.Name = ps.ReadString(); ps.ReadByte(); LogConsole(String.Format("[P] {0} connected!", temp.Name)); return 1; }
int spawnmsg(PacketStream ps) { byte id = ps.ReadByte(); short spawnx = ps.ReadShort(); short spawny = ps.ReadShort(); // float rot = ps.ReadFloat(); ps.ReadByte(); ps.ReadByte(); ps.ReadByte(); ps.ReadByte(); byte wpns = ps.ReadByte(); // 50? for (int j = 0; j < wpns; j++) { ps.ReadByte(); ps.ReadByte(); } //byte uk = ps.ReadByte(); // 0 //byte uk2 = ps.ReadByte(); //short money = ps.ReadShort(); // 200 //byte numweapons = ps.ReadByte(); // 1 //LogConsole(String.Format("{0} spawned at {1}/{2}", id, spawnx, spawny)); if (id > 0 && id < 33) { PlayerObject tmp = players[id]; tmp.X = spawnx; tmp.Y = spawny; return 1; } else return 0; //tmp.Currentweapon = wpn; //tmp.Money = money; //if (id == own_id) //{ //LogConsole(String.Format("{0} spawned with: {1} / {2} / {3} / {4} / {5} {6}", tmp.Name, spawnx, spawny,wpn,rot,wpn,uk,uk2)); //} }
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; }
/// <summary> /// This function parses the packet /// </summary> /// <param name="ar"></param> private void OnReceive(IAsyncResult ar) { EndPoint ep = new IPEndPoint(IPAddress.Any, 0); int length = serverlistSocket.EndReceiveFrom(ar, ref ep); IPEndPoint ipe = (IPEndPoint)ep; PacketStream ps = new PacketStream(buffer, length); short pkt = ps.ReadShort(); byte type = ps.ReadByte(); int retn; switch (type) { case 0x14: retn = OnUsgnServerPacket(ps); break; case 0xfb: ServerInformation svi = GetServerFromList(ep); if(svi != null) OnServerInformationReceive(ps,svi); break; default: break; } ReceiveMessages(); // start receivin' the shizzle again }
int positionRotationUpdate(PacketStream ps) { byte id = ps.ReadByte(); short x = ps.ReadShort(); short y = ps.ReadShort(); float rot = ps.ReadFloat(); if (id >= 0 && id <= 32) { PlayerObject tmp = players[id]; tmp.Id = id; tmp.X = x; tmp.Y = y; tmp.Rotation = rot; return 1; } return 0; }
/// <summary> /// Constructs the list of servers, based on the packet received from usgn.de /// </summary> /// <param name="ps"></param> /// <returns></returns> private int OnUsgnServerPacket(PacketStream ps) { short num_servers = ps.ReadShort(); for (int i = 0; i < num_servers; i++) { byte[] ipdata = new byte[4]; for (int j = 0;j < 4; j++) { ipdata[3-j] = ps.ReadByte(); } IPAddress ipa = new IPAddress(ipdata); ushort port = (ushort)ps.ReadShort(); RequestServerInformation(ipa, port); ServerInformation svi = new ServerInformation(ipa,port); serverList.Add(svi); } return num_servers; }
int positionUpdate(PacketStream ps) { byte id = ps.ReadByte(); short px = ps.ReadShort(); short py = ps.ReadShort(); PlayerObject tmp = players[id]; tmp.X = px; tmp.Y = py; return 1; }
private void OnReceive(IAsyncResult ar) { try { int length = clientSocket.EndReceive(ar); PacketStream ps = new PacketStream(buffer, length); int pktNumber = ps.ReadShort(); /*if (pktNumber % 2 == 0) important_received.Add(ps);*/ ph.process_packet(ps, pktNumber); clientSocket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(OnReceive), null); } catch (SocketException ex) { ph.LogConsole("Error in socket: " + ex.Message); } catch (ObjectDisposedException ex) { } }
int projectile(PacketStream ps) { byte player_id = ps.ReadByte();//one who throws the nade byte wpn_id = ps.ReadByte(); short x_origin = ps.ReadShort(); short y_origin = ps.ReadShort(); float angle = ps.ReadFloat(); byte uk0 = ps.ReadByte(); ps.ReadByte(); // discard 0 return 1; }
/* private void OnDisconnect(IAsyncResult ar) { clientSocket.EndDisconnect(ar); clientSocket.Close(); }*/ public void SendStream(PacketStream ps, bool important) { if (important) { ph.PacketNumber += 2; ps.setPacketNumber(ph.PacketNumber); /*important_send.Add(ph.PacketNumber, ps);*/ // important_send.Add(ps); } else { short tempPacketnum = (short)(ph.PacketNumber + 1); ps.setPacketNumber(tempPacketnum); } clientSocket.BeginSend(ps.toArray(), 0, ps.Length, SocketFlags.None, new AsyncCallback(OnSend), null); }
int chatmsg(PacketStream ps) { byte id = ps.ReadByte(); byte uk2 = ps.ReadByte(); byte strlen = ps.ReadByte(); ps.ReadByte(); string txt = ps.ReadString(strlen); if (id != 0 && players[id] != null) LogConsole(String.Format("[P] {0}: {1}", players[id].Name, txt)); else LogConsole(String.Format("[U]: {0}", txt)); return 1; }