// Analyze: modify and/or log a pocket private static Packet Analyze(Packet packet, IPEndPoint endPoint, Direction direction) { if (modifiedPackets.Contains(packet.Layout.Name)) { try { Hashtable changes = (Hashtable)modifiedPackets[packet.Layout.Name]; Hashtable blocks = PacketUtility.Unbuild(packet); foreach (BlockField blockField in changes.Keys) { PacketUtility.SetField(blocks, blockField.block, blockField.field, changes[blockField]); } packet = PacketBuilder.BuildPacket(packet.Layout.Name, protocolManager, blocks, packet.Data[0]); } catch (Exception e) { Console.WriteLine("failed to modify " + packet.Layout.Name + ": " + e.Message); Console.WriteLine(e.StackTrace); } } if (loggedPackets.Contains(packet.Layout.Name)) { LogPacket(packet, endPoint, direction); } return(packet); }
private static void ReadFromConsole() { // send text from the console in an infinite loop for (;;) { // read a line from the console string message = Console.ReadLine(); // construct a ChatFromViewer packet Hashtable blocks = new Hashtable(); Hashtable fields; fields = new Hashtable(); fields["Channel"] = (int)0; fields["Message"] = message; fields["Type"] = (byte)1; blocks[fields] = "ChatData"; fields = new Hashtable(); fields["AgentID"] = agentID; fields["SessionID"] = sessionID; blocks[fields] = "AgentData"; Packet chatPacket = PacketBuilder.BuildPacket("ChatFromViewer", protocolManager, blocks, Helpers.MSG_RELIABLE); // inject the packet proxy.InjectPacket(chatPacket, Direction.Outgoing); } }
public void OnMoveReq(GameMapAction.MoveAction moveAction) { //封包只傳往前後左右的動作 var payload = PacketBuilder.BuildPacket((int)SystemCategory.GameMapSystem, (int)GameMapCommand.MoveReq, GameMapMoveReqPayload.CreatePayload(moveAction)); SocketClientManager.Instance.Send(payload); }
public void SendLastMessage(Player player) { var values = RedisHelper.GetRedisDb(RedisHelper.RedisDbNum.MsgData).ListRange(GetSystemRedisKey(), -100, -1); var MsgInfoList = new List<Message>(); foreach (string value in values) { MsgInfoList.Add(new Message { MessageString = value }); } Send(player, PacketBuilder.BuildPacket((int)SystemCategory.MessageSystem, (int)MessageCommand.MessageResp, MessageRespPayload.CreatePayload(MessageAck.Success, MsgInfoList.ToArray()))); }
private void UserLoginReq(Player player, byte[] byteArray) { UserLoginReqPayload.ParsePayload(byteArray, out var infoData); var dbContext = SockerManager.Instance.GetApplicationContext(); //SingleOrDefault will return null if no exist. var user = dbContext.Users.Where(u => u.UserId == infoData.UserId).SingleOrDefault(); //如果用戶不存在則自動幫他創帳號 if (user == null) { Console.WriteLine("not found equal userid, created new user."); user = new User { UserId = infoData.UserId, UserPwd = infoData.UserPwd }; dbContext.Users.Add(user); dbContext.SaveChanges(); user = dbContext.Users.Where(u => u.UserId == infoData.UserId).SingleOrDefault(); //更新該玩家的資料 player.PlayerData.PlayerUid = user.PlayerUid; //未來會做成存在DB或REDIS PlayerDataSystem.Instance.SaveOneInfoDataToRedis(RedisHelper.GetRedisDb(RedisHelper.RedisDbNum.Connect), player.PlayerData); } //建立完帳戶、確認用戶帳密是否一致 //不一致就傳送失敗訊號,並且剔除使用者 if (infoData.UserPwd != user.UserPwd) { Send(player, PacketBuilder.BuildPacket((int)SystemCategory.UserSystem, (int)UserCommand.UserLoginResp, UserLoginRespPayload.CreatePayload(UserAck.AuthFail))); return; } //更新Player資料 從DB重撈 player.PlayerData = PlayerDataSystem.Instance.GetOneInfoDataFromRedis(RedisHelper.GetRedisDb(RedisHelper.RedisDbNum.Connect), user.PlayerUid); //驗證成功就通知在線上的伺服器,把人踢下線 SockerManager.Instance.PublishLoginToRedis(user.PlayerUid); //回傳成功訊息給對應的人 Send(player, PacketBuilder.BuildPacket((int)SystemCategory.UserSystem, (int)UserCommand.UserLoginResp, UserLoginRespPayload.CreatePayload(UserAck.Success))); //傳送玩家資料給他 Send(player, PacketBuilder.BuildPacket((int)SystemCategory.PlayerDataSystem, (int)PlayerDataCommand.PlayerDataResp, PlayerDataRespPayload.CreatePayload(PlayerDataAck.Success, player.PlayerData))); //儲存玩家資料進Redis PlayerDataSystem.Instance.SaveOneInfoDataToRedis(RedisHelper.GetRedisDb(RedisHelper.RedisDbNum.Connect), player.PlayerData); //回傳留言版最後一百筆資料 MessageSystem.Instance.SendLastMessage(player); //更新玩家資料 SockerManager.Instance.SavePlayerConnect(player.Connection.RemoteEndPoint.ToString(), player); }
// SayToUser: send a message to the user as in-world chat private static void SayToUser(string message) { Hashtable blocks = new Hashtable(); Hashtable fields; fields = new Hashtable(); fields["FromName"] = "Analyst"; fields["SourceID"] = new LLUUID(true); fields["OwnerID"] = agentID; fields["SourceType"] = (byte)2; fields["ChatType"] = (byte)1; fields["Audible"] = (byte)1; fields["Position"] = new LLVector3(0, 0, 0); fields["Message"] = message; blocks[fields] = "ChatData"; Packet packet = PacketBuilder.BuildPacket("ChatFromSimulator", protocolManager, blocks, Helpers.MSG_RELIABLE); proxy.InjectPacket(packet, Direction.Incoming); }
public void Connected() { lblName.Text = Client.Network.LoginValues["first_name"] + " " + Client.Network.LoginValues["last_name"]; // MoneyBalanceRequest Hashtable blocks = new Hashtable(); Hashtable fields = new Hashtable(); blocks = new Hashtable(); fields = new Hashtable(); fields["AgentID"] = Client.Network.AgentID; fields["TransactionID"] = LLUUID.GenerateUUID(); blocks[fields] = "MoneyData"; Packet packet = PacketBuilder.BuildPacket("MoneyBalanceRequest", Client.Protocol, blocks, Helpers.MSG_RELIABLE); Client.Network.SendPacket(packet); }
public void GameMapMoveReq(Player player, byte[] byteArray) { GameMapMoveReqPayload.ParsePayload(byteArray, out var moveAction); var ackCode = GameMapAck.Success; if (!GameMapsDict.TryGetValue(player.PlayerData.MapSeed, out var gameMap)) { Console.WriteLine("不存在的地圖"); ackCode = GameMapAck.NoExistMapSeed; } //檢查面向,依照面向的位置往前後左右移動,然後再計算有沒有超界 if (!isBorder(gameMap, player, moveAction)) { Console.WriteLine("超越地圖邊界、不存在的動作"); ackCode = GameMapAck.OverBorder; } var payload = GameMapMoveRespPayload.CreatePayload(ackCode, player.PlayerData.PosX, player.PlayerData.PosY, player.PlayerData.PlayeyFace); Send(player, PacketBuilder.BuildPacket((int)SystemCategory.GameMapSystem, (int)GameMapCommand.MoveResp, payload)); }
private void cmdFind_Click(object sender, System.EventArgs e) { lstFind.Items.Clear(); Hashtable blocks = new Hashtable(); Hashtable fields = new Hashtable(); fields["QueryID"] = LLUUID.GenerateUUID(); fields["QueryFlags"] = (uint)1; fields["QueryStart"] = (int)0; fields["QueryText"] = txtFind.Text; blocks[fields] = "QueryData"; fields = new Hashtable(); fields["AgentID"] = Client.Network.AgentID; fields["SessionID"] = Client.Network.SessionID; blocks[fields] = "AgentData"; Packet packet = PacketBuilder.BuildPacket("DirFindQuery", Client.Protocol, blocks, Helpers.MSG_RELIABLE); Client.Network.SendPacket(packet); }
// CmdInject: handle an /inject command private static void CmdInject(string[] words) { if (words.Length < 2) { SayToUser("Usage: /inject <packet file> [value]"); } else { string[] valueArray = new string[words.Length - 2]; Array.Copy(words, 2, valueArray, 0, words.Length - 2); string value = String.Join(" ", valueArray); FileStream fs = null; StreamReader sr = null; Direction direction = Direction.Incoming; string name = null; Hashtable blocks = new Hashtable(); string block = null; Hashtable fields = new Hashtable(); try { fs = File.OpenRead(words[1] + ".packet"); sr = new StreamReader(fs); string line; while ((line = sr.ReadLine()) != null) { Match match; if (name == null) { match = (new Regex(@"^\s*(in|out)\s+(\w+)\s*$")).Match(line); if (!match.Success) { SayToUser("expecting direction and packet name, got: " + line); return; } string lineDir = match.Groups[1].Captures[0].ToString(); string lineName = match.Groups[2].Captures[0].ToString(); if (lineDir == "in") { direction = Direction.Incoming; } else if (lineDir == "out") { direction = Direction.Outgoing; } else { SayToUser("expecting 'in' or 'out', got: " + line); return; } name = lineName; } else { match = (new Regex(@"^\s*\[(\w+)\]\s*$")).Match(line); if (match.Success) { if (block != null) { blocks[fields] = block; } block = match.Groups[1].Captures[0].ToString(); fields = new Hashtable(); continue; } if (block == null) { SayToUser("expecting block name, got: " + line); return; } match = (new Regex(@"^\s*(\w+)\s*=\s*(.*)$")).Match(line); if (match.Success) { string lineField = match.Groups[1].Captures[0].ToString(); string lineValue = match.Groups[2].Captures[0].ToString(); if (lineValue == "$Value") { fields[lineField] = MagicCast(name, block, lineField, value); } else if (lineValue == "$UUID") { fields[lineField] = new LLUUID(true); } else if (lineValue == "$AgentID") { fields[lineField] = agentID; } else if (lineValue == "$SessionID") { fields[lineField] = sessionID; } else { fields[lineField] = MagicCast(name, block, lineField, lineValue); } continue; } SayToUser("expecting block name or field, got: " + line); return; } } if (name == null) { SayToUser("expecting direction and packet name, got EOF"); return; } if (block != null) { blocks[fields] = block; } byte flags = Helpers.MSG_RELIABLE; if (protocolManager.Command(name).Encoded) { flags |= Helpers.MSG_ZEROCODED; } Packet packet = PacketBuilder.BuildPacket(name, protocolManager, blocks, flags); proxy.InjectPacket(packet, direction); SayToUser("injected " + words[1]); } catch (Exception e) { SayToUser("failed to inject " + words[1] + ": " + e.Message); } finally { if (fs != null) { fs.Close(); } if (sr != null) { sr.Close(); } } } }
public void SendMsgToAll(Message[] infoDatas) { Broadcast(PacketBuilder.BuildPacket((int)SystemCategory.MessageSystem, (int)MessageCommand.MessageResp, MessageRespPayload.CreatePayload(MessageAck.Success, infoDatas.ToArray()))); }
private void cmdImport_Click(object sender, System.EventArgs e) { OpenFileDialog openDialog = new OpenFileDialog(); openDialog.Title = "Open Prim.Blender File"; openDialog.Filter = "All files (*.*)|*.*|Prim files (*.prims)|*.prims"; openDialog.FilterIndex = 2; if (openDialog.ShowDialog() != DialogResult.OK) { return; } XmlDocument xml = new XmlDocument(); XmlNodeList list = null; try { // Try to load the xml file xml.Load(openDialog.FileName); //If there is a document and it has children, if (xml != null && xml.HasChildNodes) { //Get the children into the temp list list = xml.GetElementsByTagName("primitive"); } else { txtLog.AppendText("ERROR: Failed to parse " + openDialog.FileName + "\n"); return; } } catch (Exception err) { txtLog.AppendText("ERROR: " + err.ToString() + "\n"); return; } foreach (XmlNode node in list) { txtLog.AppendText("Parsing primitive " + node.Attributes["key"].Value + "\n"); XmlNode properties = node["properties"]; PrimObject prim = new PrimObject(new LLUUID("8955674724cb43ed920b47caed15465f")); prim.Material = Convert.ToUInt16(properties["material"].Attributes["val"].Value); prim.Name = node.Attributes["key"].Value; // Either PathBegin/End or ProfileBegin/End should be dimple prim.PathBegin = PrimObject.PathBeginByte(Convert.ToSingle(properties["cut"].Attributes["x"].Value)); prim.PathEnd = PrimObject.PathEndByte(Convert.ToSingle(properties["cut"].Attributes["y"].Value)); prim.PathRadiusOffset = PrimObject.PathRadiusOffsetByte(Convert.ToSingle(properties["radiusoffset"].Attributes["val"].Value)); prim.PathRevolutions = PrimObject.PathRevolutionsByte(Convert.ToSingle(properties["revolutions"].Attributes["val"].Value)); prim.PathScaleX = PrimObject.PathScaleByte(Convert.ToSingle(properties["topsize"].Attributes["x"].Value)); prim.PathScaleY = PrimObject.PathScaleByte(Convert.ToSingle(properties["topsize"].Attributes["y"].Value)); prim.PathShearX = PrimObject.PathShearByte(Convert.ToSingle(properties["topshear"].Attributes["x"].Value)); prim.PathShearY = PrimObject.PathShearByte(Convert.ToSingle(properties["topshear"].Attributes["y"].Value)); prim.PathSkew = PrimObject.PathSkewByte(Convert.ToSingle(properties["skew"].Attributes["val"].Value)); prim.PathTaperX = PrimObject.PathTaperByte(Convert.ToSingle(properties["taper"].Attributes["x"].Value)); prim.PathTaperY = PrimObject.PathTaperByte(Convert.ToSingle(properties["taper"].Attributes["y"].Value)); prim.PathTwist = PrimObject.PathTwistByte(Convert.ToSingle(properties["twist"].Attributes["y"].Value)); prim.PathTwistBegin = PrimObject.PathTwistByte(Convert.ToSingle(properties["twist"].Attributes["x"].Value)); prim.ProfileBegin = PrimObject.ProfileBeginByte(Convert.ToSingle(properties["cut"].Attributes["x"].Value)); prim.ProfileEnd = PrimObject.ProfileEndByte(Convert.ToSingle(properties["cut"].Attributes["y"].Value)); ushort curve = Convert.ToUInt16(properties["type"].Attributes["val"].Value); switch (curve) { case 0: // Box prim.ProfileCurve = 1; prim.PathCurve = 16; break; case 1: // Cylinder prim.ProfileCurve = 0; prim.PathCurve = 16; break; case 2: // Prism prim.ProfileCurve = 3; prim.PathCurve = 16; break; case 3: // Sphere prim.ProfileCurve = 5; prim.PathCurve = 32; break; case 4: // Torus prim.ProfileCurve = 0; prim.PathCurve = 32; break; case 5: // Tube prim.ProfileCurve = 1; prim.PathCurve = 32; break; case 6: // Ring prim.ProfileCurve = 3; prim.PathCurve = 16; break; } prim.ProfileHollow = Convert.ToUInt32(properties["hollow"].Attributes["val"].Value); prim.Rotation = new LLQuaternion( Convert.ToSingle(properties["rotation"].Attributes["x"].Value), Convert.ToSingle(properties["rotation"].Attributes["y"].Value), Convert.ToSingle(properties["rotation"].Attributes["z"].Value), Convert.ToSingle(properties["rotation"].Attributes["s"].Value)); prim.Scale = new LLVector3( Convert.ToSingle(properties["size"].Attributes["x"].Value), Convert.ToSingle(properties["size"].Attributes["y"].Value), Convert.ToSingle(properties["size"].Attributes["z"].Value)); LLVector3 position = new LLVector3( Convert.ToSingle(properties["position"].Attributes["x"].Value) + (float)Client.Avatar.Position.X, Convert.ToSingle(properties["position"].Attributes["y"].Value) + (float)Client.Avatar.Position.Y, Convert.ToSingle(properties["position"].Attributes["z"].Value) + (float)Client.Avatar.Position.Z + 50.0F); prim.Position = position; CurrentPrim = prim; WaitingOnUpdate = true; Client.CurrentRegion.RezObject(prim, position, new LLVector3(Client.Avatar.Position)); while (WaitingOnUpdate) { System.Threading.Thread.Sleep(100); Application.DoEvents(); } txtLog.AppendText("Rezzed primitive with UUID " + CurrentPrim.UUID + " and ID " + CurrentPrim.ID + " \n"); Hashtable blocks = new Hashtable(); Hashtable fields = new Hashtable(); /*fields["ObjectLocalID"] = CurrentPrim.ID; * blocks[fields] = "ObjectData"; * * fields = new Hashtable(); * * fields["AgentID"] = Client.Network.AgentID; * blocks[fields] = "AgentData"; * * Packet packet = PacketBuilder.BuildPacket("ObjectSelect", Client.Protocol, blocks, Helpers.MSG_RELIABLE); * Client.Network.SendPacket(packet); * * System.Threading.Thread.Sleep(100);*/ Packet packet; byte[] byteArray = new byte[12]; Array.Copy(position.GetBytes(), byteArray, 12); fields["Data"] = byteArray; fields["Type"] = (byte)9; fields["ObjectLocalID"] = CurrentPrim.ID; blocks[fields] = "ObjectData"; fields = new Hashtable(); fields["AgentID"] = Client.Network.AgentID; blocks[fields] = "AgentData"; packet = PacketBuilder.BuildPacket("MultipleObjectUpdate", Client.Protocol, blocks, Helpers.MSG_RELIABLE); Client.Network.SendPacket(packet); Client.Network.SendPacket(packet); Client.Network.SendPacket(packet); System.Threading.Thread.Sleep(500); } }