public MainForm() { InitializeComponent(); Shown += (s, e) => GUIHelpers.Transitions.ShowForm(this, 1, 0.1, 10); GUIHelpers.DragControl dc = new GUIHelpers.DragControl(this); dc.Add(pnlHeader); btnExit.Click += (s, e) => Process.GetCurrentProcess().Kill(); SetHandlers(); SetDefaults(); btnImage.Click += (s, e) => { for (int i = 0; i < 6; i++) { char[] arr = new char[6] { '#', '#', '#', '#', '#', '#' }; arr[i] = '@'; C_CHAT packet = new C_CHAT(); packet.Message = $"<FONT>{new string(arr)}</FONT>"; packet.TextOffset = 10; packet.Channel = Tera.Core.Game.ChatChannel.Global; PacketController.Send(packet); } }; }
private unsafe int WSARecv_Hook(IntPtr socket, ref WSABuffer buffer, int bufferCount, out int bytesTransferred, ref int socketFlags, IntPtr nativeOverlapped, IntPtr completionRoutine) { int result = Ws2_32.WSARecv(socket, ref buffer, bufferCount, out bytesTransferred, ref socketFlags, nativeOverlapped, completionRoutine); if (_socket == socket) { if (bytesTransferred > ushort.MaxValue || bytesTransferred == 0 || bufferCount != 1) { return(result); } _serverPackets++; byte[] data = buffer.Buffer.ExtractBuffer(bytesTransferred); switch (_serverPackets) { case 1: PacketController.Preinitialize(this, data); break; case 2: sKey1 = data; break; case 3: sKey2 = data; PacketController.Initialize(cKey1, cKey2, sKey1, sKey2); break; default: byte[] processed = PacketController.ProcessServerData(data); if (processed.Take(4).SequenceEqual(GameClient.C_SIGNATURE)) { Marshal.Copy(processed, 4, buffer.Buffer + bytesTransferred, processed.Length - 4); bytesTransferred += processed.Length - 4; } break; } } return(0); }
/// <summary> /// Adds a new client to the list /// </summary> /// <param name="ipEndPoint"></param> public void AddClient(NetConnection _connection, IPEndPoint _ipEndPoint) { if (!clients.ContainsKey(_ipEndPoint)) { //TODO get the username of the player that is logging in and fetch the data ClientData newClient = new ClientData(_connection, ClientData.GetFreeID(clients)); clients.Add(_ipEndPoint, newClient); foreach (var client in clients.Values) { if (client.Equals(newClient)) { continue; } //Tell all clients, a new client connected PacketController.getInstance().SendNewClientConnected(newClient); } PacketController.getInstance().SendClientConnectAnswer(newClient); if (debugMode) { Debug.Log("Created client with id '" + newClient.ID + "'!"); } } }
private void UpdatePosition() { if (transform.position == LastPosition) { return; } LastPosition = transform.position; Position = transform.position; PacketController.getInstance().SendNetworkObjectPosition(this); }
private unsafe int closesocket_Hook(IntPtr socket) { if (socket == _socket) { _socket = IntPtr.Zero; _clientPackets = 0; _serverPackets = 0; PacketController.Finish(); } return(Ws2_32.closesocket(socket)); }
private void btnSend_Click(object sender, EventArgs e) { PacketReflectionInfo info = PacketController.Client.Processor.Serializer.Info[cbxOps.Text]; Object pObject = Activator.CreateInstance(info.Type); int length = info.Fields.Length; for (int i = 0; i < length; i++) { FieldInfo field = info.Fields[i]; field.SetValue(pObject, _controls[i].FieldValue); } PacketController.Send((Packet)pObject); }
private void Start() { ID = Utils.GetFreeID(); Debug.Log("PrefabID: " + ID); Server.getInstance().netObjs.Add(ID, this); Position = transform.position; Rotation = transform.rotation.eulerAngles; if (!Server.getInstance().isStarted) { return; } PacketController.getInstance().SendNetworkObjectSpawn(this); }
/// <summary> /// Removes a client from the list and also removes the transform if one exists /// </summary> /// <param name="ipEndPoint"></param> public void RemoveClient(IPEndPoint ipEndPoint) { if (clients.ContainsKey(ipEndPoint)) { ClientData _client = clients[ipEndPoint]; //inform all players, that a client disconnected PacketController.getInstance().SendClientDisconnect(clients[ipEndPoint]); if (clientsTransform.ContainsKey(_client.ID)) { GameServerCycle.getInstance() .DestroyNetObject(clientsTransform[clients[ipEndPoint].ID]); } clientsTransform.Remove(clients[ipEndPoint].ID); clients.Remove(ipEndPoint); } }
private void btnSend_Click(object sender, EventArgs e) { string[] splitted = tbData.Text.Split(SPLITTER); if (splitted == null || splitted.Length < 4) { MessageBox.Show("HEX-code contains to little data.", "Terax", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } byte[] data = new byte[splitted.Length]; int length = data.Length; for (int i = 0; i < length; i++) { if (!splitted[i].IsHex()) { MessageBox.Show("HEX-code contains wrong data.", "Terax", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } data[i] = splitted[i].ToByte(); } PacketDirection direction = (PacketDirection)cbxDirection.SelectedIndex; if (cbEncrypt.Selected) { if (lblOpName.Text.Equals(NONE)) { MessageBox.Show("Byte-code is wrong. Check your OpCode.", "Terax", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (data.Length != (data[0] | data[1] << 8)) { MessageBox.Show($"Wrong length of hex-code. Should be: {(data[0] | data[1] << 8)}", "Terax", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } switch (direction) { case PacketDirection.ClientToServer: PacketController.Send(new RawPacket(data, direction)); break; case PacketDirection.ServerToClient: PacketController.Client.CPacket = new RawPacket(data, direction); PacketController.Send(new RawPacket(new byte[] { 0x04, 0x00, 0xFE, 0xFF }, PacketDirection.ClientToServer)); break; } } else { PacketController.Send(data, direction); } }
void Awake() { m_recvBuffer = new byte[BufferSize]; m_pcFromServer = new PacketController(); m_pcFromP2P = new PacketController(); // GameServer Connection Context m_client = new TcpClient(); m_client.OnReceived += m_pcFromServer.Receive; // Host Connection Context m_host = new TcpServer(); m_host.OnReceived += m_pcFromP2P.Receive; // Guest Connection Context m_guest = new TcpClient(); m_guest.OnReceived += m_pcFromP2P.Receive; }
private void CalculatePlayerDeathTime() { foreach (ClientData _client in Server.getInstance().clients.Values) { if (_client == null || !_client.IsDead) { continue; } if (_client.DeathTime > 0) { _client.DeathTime -= Time.deltaTime; } else { Server.getInstance().clients[_client.Connection.RemoteEndPoint] = new ClientData(_client.Connection, _client.ID); SpawnPlayer(_client); PacketController.getInstance().SendPlayerRespawn(_client); } } }
private unsafe int send_Hook(IntPtr socket, IntPtr buffer, int length, int flags) { if (_socket == socket) { if (length > ushort.MaxValue || length == 0) { return(Ws2_32.send(socket, buffer, length, flags)); } _clientPackets++; byte[] data = buffer.ExtractBuffer(length); switch (_clientPackets) { case 1: cKey1 = data; break; case 2: cKey2 = data; break; default: return(PacketController.ProcessClientData(data)); } return(Ws2_32.send(socket, buffer, length, flags)); } return(Ws2_32.send(socket, buffer, length, flags)); }
private void OnDestroy() { Server.getInstance().netObjs.Remove(ID); PacketController.getInstance().SendNetworkObjectDestroy(this); }
protected void dvDataSource_Inserting(object sender, ObjectDataSourceMethodEventArgs e) { Packet p = e.InputParameters["entityToInsert"] as Packet; PacketController.ValidateInsertCode(p.Code); }
protected void dvDataSource_Updating(object sender, ObjectDataSourceMethodEventArgs e) { Packet p = e.InputParameters["newEntity"] as Packet; PacketController.ValidateUpdateCode(p.ID, p.Code); }
public void UpdatePlayerPosition(ClientData _client) { Vector3 dir; switch (_client.MoveDir) { case MoveDirs.UP: dir = Vector3.forward; break; case MoveDirs.UPRIGHT: dir = Vector3.forward + Vector3.right; break; case MoveDirs.RIGHT: dir = Vector3.right; break; case MoveDirs.RIGHTDOWN: dir = Vector3.back + Vector3.right; break; case MoveDirs.DOWN: dir = Vector3.back; break; case MoveDirs.DOWNLEFT: dir = Vector3.back + Vector3.left; break; case MoveDirs.LEFT: dir = Vector3.left; break; case MoveDirs.LEFTUP: dir = Vector3.left + Vector3.forward; break; case MoveDirs.NONE: dir = Vector3.zero; break; default: throw new ArgumentOutOfRangeException(); } Transform player = Server.getInstance().clientsTransform[_client.ID]; player.rotation = Quaternion.Euler(_client.Rotation); player.Translate(dir.normalized * _client.Speed * Time.deltaTime, Space.World); _client.Position = player.transform.position; if (_client.LastPosition == _client.Position) { return; } if (_client.WantsPredict) { _client.moveTime++; } _client.LastPosition = _client.Position; PacketController.getInstance().SendPlayerPosition(_client); }
private void ProcessMessage(byte id, NetIncomingMessage message) { //Protokoll : [Byte], [Value], [Value], ... ClientData _client = clients[message.SenderEndPoint]; switch (id) { case 0x0: //positionupdate _client.MoveDir = (MoveDirs)message.ReadInt32(); _client.Rotation = new Vector3(message.ReadFloat(), message.ReadFloat(), message.ReadFloat()); if (_client.WantsPredict) { float movetime = message.ReadFloat(); if (movetime <= _client.moveTime) { if (debugMode) { Debug.Log("Client movetime mismatch! Client(" + _client.ID + "):" + movetime + " -- " + _client.moveTime); } } } break; case 0x1: //gamestate List <ClientData> _clients = (from client in clients where client.Value.ID != clients[message.SenderEndPoint].ID select client.Value).ToList(); foreach (ClientData c in _clients) { if (c.Connection == null) { continue; } PacketController.getInstance().SendPlayerList(c, clients[message.SenderEndPoint].Connection); } foreach (var netObject in netObjs.Values) { PacketController.getInstance() .SendNetworkObjectSpawn(netObject, clients[message.SenderEndPoint].Connection); } Debug.Log("Sent PLAYERLIST to " + clients[message.SenderEndPoint].ID); /*Takes me one step closer to the * edge and I'm about to */ break; case 0x3: //statsUpdate short defenderId = message.ReadInt16(); ClientData defender = (from client in clients where client.Value.ID == defenderId select client.Value).ToList()[0]; ClientData attacker = clients[message.SenderEndPoint]; HealthController.getInstance().CalculatePlayerHitpoints(attacker, defender); foreach (ClientData client in clients.Values) { PacketController.getInstance().SendPlayerHPUpdate(defender, client.Connection); } break; case 0x4: //update animation ClientData animPlayer = clients[message.SenderEndPoint]; animPlayer.AnimationState = (AnimationStates)message.ReadInt32(); List <ClientData> _others = Utils.GetOtherClients(animPlayer, clients); foreach (ClientData c in _others) { PacketController.getInstance().SendPlayerAnimationState(animPlayer, c.Connection); } break; case 0x5: //chat event //TODO add chat controller and check message for different parameter //TODO add differenct chat channels //TODO make it possible to write a personal message to other players //TODO add commands foreach (ClientData rec in clients.Values) { PacketController.getInstance().SendChatMessage(clients[message.SenderEndPoint], rec.Connection, message.ReadString()); } break; case 0x6: //team join int teamId = message.ReadInt32(); if (TeamController.getInstance().AddToTeam(clients[message.SenderEndPoint], teamId)) { GameServerCycle.getInstance().SpawnPlayer(clients[message.SenderEndPoint]); } foreach (var receiver in clients.Values) { PacketController.getInstance() .SendPlayerTeamJoin(clients[message.SenderEndPoint], receiver.Connection); } break; case 0x7: //farming short interactEntityID = message.ReadInt16(); Vector3 targetPos = new Vector3(message.ReadFloat(), message.ReadFloat(), message.ReadFloat()); if (netObjs.ContainsKey(interactEntityID) && Utils.CanInteract(clients[message.SenderEndPoint], targetPos)) { //TODO add multiple ressources and dont return on another prefab as tree //TODO get a list of interactable types / mineable types //TODO add a interact function to every type of entity and call the function of the networkobject if (netObjs[interactEntityID].prefabType != PrefabTypes.TREE) { return; } Vector3 dropLocation = Utils.CalculateDropLocation(netObjs[interactEntityID].Position, (int)GameConstants.dropRange); GameServerCycle.getInstance().DestroyNetObject(netObjs[interactEntityID]); PrefabController.getInstance().SpawnPrefab(PrefabTypes.WOOD, dropLocation); } break; case 0x8: //addItemRequest / pickup Item //TODO add picker //short pickerID = message.ReadInt16(); short netId = message.ReadInt16(); if (netObjs.ContainsKey(netId) && Utils.CanInteract(clients[message.SenderEndPoint], netObjs[netId].Position)) { //TODO move into own class as an interact event and check what happens if a player interacts with an item (pickup, destroy etc.) //GameServerCycle.getInstance().DestroyNetObject(netObjs[netId].gameObject); //var response = server.CreateMessage(); //response.Write((byte) PacketTypes.PICKUP); //response.Write(netId); //server.SendToAll(response, NetDeliveryMethod.ReliableUnordered); //TODO check add inventory attribute to the clientdata } break; case 0x9: //weapon change event _client.WeaponState = (WeaponStates)message.ReadInt32(); if (debugMode) { Debug.Log("Changed weapon of " + _client.ID + " to " + _client.WeaponState); } PacketController.getInstance().SendWeaponChange(_client); break; case 0x10: //spawn // netId = message.ReadInt16(); break; case 0x11: //attack request (spells, projectiles) PrefabController.getInstance().SpawnPrefab(PrefabTypes.ARROW, _client.Position); break; } }