From 3487d8e7fb81df1ee4b4f81431c999ec32849786 Mon Sep 17 00:00:00 2001 From: hackgames15 Date: Sun, 8 Sep 2024 07:22:40 +0000 Subject: [PATCH] Pending changes exported from your codespace --- .save/create_Table.py | 9 +++++ .save/create_Value.py | 22 +++++++++++ .save/set_Value.py | 19 +++++++++ LICENSE | 21 ---------- README.md | 91 ------------------------------------------- database.py | 27 +++++++++++++ index.php | 27 ------------- server.py | 74 +++++++++++++++++++++++++++++++++++ test2.py | 78 +++++++++++++++++++++++++++++++++++++ 9 files changed, 229 insertions(+), 139 deletions(-) create mode 100644 .save/create_Table.py create mode 100644 .save/create_Value.py create mode 100644 .save/set_Value.py delete mode 100644 LICENSE delete mode 100644 README.md create mode 100644 database.py delete mode 100644 index.php create mode 100644 server.py create mode 100644 test2.py diff --git a/.save/create_Table.py b/.save/create_Table.py new file mode 100644 index 00000000..aaf9f651 --- /dev/null +++ b/.save/create_Table.py @@ -0,0 +1,9 @@ +import argparse +import os + +# Setting up argparse for command-line arguments +parser = argparse.ArgumentParser() +parser.add_argument('--name', help="name Table") +args = parser.parse_args() + +os.makedirs(args.name, exist_ok=True) diff --git a/.save/create_Value.py b/.save/create_Value.py new file mode 100644 index 00000000..37ee286d --- /dev/null +++ b/.save/create_Value.py @@ -0,0 +1,22 @@ +import argparse +import os + +# Setting up argparse for command-line arguments +parser = argparse.ArgumentParser() +parser.add_argument('--name_table', help="Name of the directory", required=True) +parser.add_argument('--name_value', help="Name of the value/file", required=True) +parser.add_argument('--data', help="Data to write to the file", required=False) +args = parser.parse_args() + +try: + # Write the data to the file + with open(f"{args.name_table}/{args.name_value}.txt", "w") as file: + if args.data is not None: + file.write(args.data) + else: + raise ValueError("No data provided") + +except Exception as e: + # In case of error, prompt for user input + with open(f"{args.name_table}/{args.name_value}.txt", "w") as file: + file.write(input("text or number to save> ")) diff --git a/.save/set_Value.py b/.save/set_Value.py new file mode 100644 index 00000000..3a8f2334 --- /dev/null +++ b/.save/set_Value.py @@ -0,0 +1,19 @@ +import argparse +import os + +# Setting up argparse for command-line arguments +parser = argparse.ArgumentParser() +parser.add_argument('--name_table', help="Name of the directory", required=True) +parser.add_argument('--name_value', help="Name of the value/file", required=True) +parser.add_argument('--data', help="Data to write to the file", required=False) +args = parser.parse_args() +file = f"{args.name_table}/{args.name_value}" + +try: + if args.data is not None: + file.write(args.data) + else: + raise ValueError("No data provided") + +except Exception as e: + file.write(input("text or number to save> ")) diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 4b1ad51b..00000000 --- a/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ - MIT License - - Copyright (c) Microsoft Corporation. All rights reserved. - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE diff --git a/README.md b/README.md deleted file mode 100644 index 46e2e3c5..00000000 --- a/README.md +++ /dev/null @@ -1,91 +0,0 @@ -# Try Out Development Containers: PHP - -[![Open in Remote - Containers](https://img.shields.io/static/v1?label=Remote%20-%20Containers&message=Open&color=blue&logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/microsoft/vscode-remote-try-php) - -A **development container** is a running [Docker](https://www.docker.com) container with a well-defined tool/runtime stack and its prerequisites. You can try out development containers with **[GitHub Codespaces](https://github.com/features/codespaces)** or **[Visual Studio Code Remote - Containers](https://aka.ms/vscode-remote/containers)**. - -This is a sample project that lets you try out either option in a few easy steps. We have a variety of other [vscode-remote-try-*](https://github.com/search?q=org%3Amicrosoft+vscode-remote-try-&type=Repositories) sample projects, too. - -> **Note:** If you already have a Codespace or dev container, you can jump to the [Things to try](#things-to-try) section. - -## Setting up the development container - -### GitHub Codespaces -Follow these steps to open this sample in a Codespace: -1. Click the Code drop-down menu and select the **Open with Codespaces** option. -1. Select **+ New codespace** at the bottom on the pane. - -For more info, check out the [GitHub documentation](https://docs.github.com/en/free-pro-team@latest/github/developing-online-with-codespaces/creating-a-codespace#creating-a-codespace). - -### VS Code Remote - Containers - -If you already have VS Code and Docker installed, you can click the badge above or [here](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/microsoft/vscode-remote-try-php) to get started. Clicking these links will cause VS Code to automatically install the Remote - Containers extension if needed, clone the source code into a container volume, and spin up a dev container for use. - -Follow these steps to open this sample in a container using the VS Code Remote - Containers extension: - -1. If this is your first time using a development container, please ensure your system meets the pre-reqs (i.e. have Docker installed) in the [getting started steps](https://aka.ms/vscode-remote/containers/getting-started). - -2. To use this repository, you can either open the repository in an isolated Docker volume: - - - Press F1 and select the **Remote-Containers: Try a Sample...** command. - - Choose the "PHP" sample, wait for the container to start, and try things out! - > **Note:** Under the hood, this will use the **Remote-Containers: Clone Repository in Container Volume...** command to clone the source code in a Docker volume instead of the local filesystem. [Volumes](https://docs.docker.com/storage/volumes/) are the preferred mechanism for persisting container data. - - Or open a locally cloned copy of the code: - - - Clone this repository to your local filesystem. - - Press F1 and select the **Remote-Containers: Open Folder in Container...** command. - - Select the cloned copy of this folder, wait for the container to start, and try things out! - -## Things to try - -Once you have this sample opened, you'll be able to work with it like you would locally. - -> **Note:** This container runs as a non-root user with sudo access by default. Comment out `"remoteUser": "vscode"` in `.devcontainer/devcontainer.json` if you'd prefer to run as root. - -Some things to try: - -1. **Edit:** - - Open `index.php` - - Try adding some code and check out the language features. - - Notice that PHP debugging and IntelliSense are already included in the container since the `.devcontainer/devcontainer.json` lists `"felixfbecker.php-debug"`, `"bmewburn.vscode-intelephense-client"`, and `"mrmlnc.vscode-apache"` as extensions to install automatically when the container is created. -1. **Terminal:** Press ctrl+shift+\` and type `uname` and other Linux commands from the terminal window. -1. **Run and Debug:** - - Open `index.php` - - Add a breakpoint (e.g. on line 4). - - Press F5 to launch the app in the container. - - Once the breakpoint is hit, try hovering over variables, examining locals, and more. -1. **Running a server:** - - From the terminal, run `php -S 0.0.0.0:8000` - - Click "Open in Browser" in the notification that appears to access the web app on this new port. - - You can view an organized table of your forwarded ports in the 'Ports' view, which can be accessed with the command **Ports: Focus on Ports View**. - - Notice port 8000 in the 'Ports' view is labeled "Hello Remote World." In `devcontainer.json`, you can set `"portsAttributes"`, such as a label for your forwarded ports and the action to be taken when the port is autoforwarded. - - Look back at the terminal, and you should see the output from your site navigations. - - Edit the text on line 21 in `index.php` and refresh the page to see the changes immediately take effect. -1. **Attach debugger to the server:** - - Follow the previous steps to start up a PHP server and open a browser on port `8000` - - Press F1 and select the **View: Show Debug** command. - - Pick "Listen for XDebug" from the dropdown. - - Press F5 to attach the debugger. - - Add a breakpoint to `index.php` if you haven't already. - - Reload your browser window. - - Once the breakpoint is hit, try hovering over variables, examining locals, and more. - -## Contributing - -This project welcomes contributions and suggestions. Most contributions require you to agree to a -Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us -the rights to use your contribution. For details, visit https://cla.microsoft.com. - -When you submit a pull request, a CLA-bot will automatically determine whether you need to provide -a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions -provided by the bot. You will only need to do this once across all repos using our CLA. - -This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). -For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or -contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. - -## License - -Copyright © Microsoft Corporation All rights reserved.
-Licensed under the MIT License. See LICENSE in the project root for license information. diff --git a/database.py b/database.py new file mode 100644 index 00000000..4c9940d4 --- /dev/null +++ b/database.py @@ -0,0 +1,27 @@ +print("install") # Fixing the print statement +print("") +download = ["pip install requests"] +for w in download: + print(w) + +print("") +try: + import argparse + import requests + import os + + # Setting up argparse for command-line arguments + parser = argparse.ArgumentParser() + parser.add_argument('install', help="Install argument") + args = parser.parse_args() + + if args.install == "install": + os.makedirs(".save", exist_ok=True) + print("Directory '.save' created successfully.") + with open(".save/create_Table.py", "w") as file: + file.write(requests.get('https://hackgames15.github.io/database/create_Table.txt').text) + with open(".save/create_Value.py", "w") as file: + file.write(requests.get('https://hackgames15.github.io/database/create_value.txt').text) + +except Exception as e: + print(f"error: {e}") \ No newline at end of file diff --git a/index.php b/index.php deleted file mode 100644 index f15e9353..00000000 --- a/index.php +++ /dev/null @@ -1,27 +0,0 @@ - - - - - Visual Studio Code Remote :: PHP - - - - - \ No newline at end of file diff --git a/server.py b/server.py new file mode 100644 index 00000000..1a1633cc --- /dev/null +++ b/server.py @@ -0,0 +1,74 @@ +import socket +import threading +import json + +# Server settings +HOST = '127.0.0.1' # Localhost +PORT = 3500 +# Read port from config.json +try: + with open("config.json", "r") as file: + config = json.load(file) + PORT = config.get("port", 3500) # Default port if not found +except Exception as e: + print(e) + +server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +server.bind((HOST, PORT)) +server.listen() + +clients = [] +nicknames = [] + +# Broadcast messages to all clients +def broadcast(message): + for client in clients: + try: + client.send(message) + except: + # Handle broken connections + client.close() + clients.remove(client) + +# Handle client connection +def handle_client(client): + while True: + try: + # Receive and broadcast messages + message = client.recv(1024) + if not message: + # Connection was closed + break + broadcast(message) + except (ConnectionResetError, socket.error): + # Handle disconnection or socket error + break + + # Remove and close client + index = clients.index(client) + clients.remove(client) + client.close() + nickname = nicknames[index] + broadcast(f'{nickname} has left the chat!'.encode('utf-8')) + nicknames.remove(nickname) + +# Receive clients +def receive(): + while True: + client, address = server.accept() + print(f"Connected with {str(address)}") + + client.send("Server: Enter your nickname: ".encode('utf-8')) + nickname = client.recv(1024).decode('utf-8') + nicknames.append(nickname) + clients.append(client) + + print(f'Nickname of the client is {nickname}!') + broadcast(f'Server: {nickname} joined the chat!'.encode('utf-8')) + client.send('Client: Connected to the server!'.encode('utf-8')) + + thread = threading.Thread(target=handle_client, args=(client,)) + thread.start() + +print("Server is Run") +receive() \ No newline at end of file diff --git a/test2.py b/test2.py new file mode 100644 index 00000000..14487272 --- /dev/null +++ b/test2.py @@ -0,0 +1,78 @@ +import socket +import threading +import tkinter as tk +from tkinter import simpledialog, scrolledtext, messagebox + +# Client settings +HOST = '127.0.0.1' +PORT = 5000 + +# Initialize socket +client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +client.connect((HOST, PORT)) + +class ChatClient: + def __init__(self, root): + self.root = root + self.root.title("Chat Application") + self.root.configure(bg="#1E1E1E") + + self.server_ip = tk.Label(root,text=f"server_ip: {HOST}") + self.server_ip.pack() + self.server_port = tk.Label(root,text=f"server_port: {PORT}") + self.server_port.pack() + + self.chat_label = tk.Label(root, text="Chat:") + self.chat_label.pack(padx=20, pady=5) + + self.text_area = scrolledtext.ScrolledText(root) + self.text_area.pack(padx=20, pady=5) + self.text_area.config(state='disabled') + + self.msg_label = tk.Label(root, text="Message:") + self.msg_label.pack(padx=20, pady=5) + + self.msg_entry = tk.Entry(root, width=50) + self.msg_entry.pack(padx=20, pady=5) + + self.send_button = tk.Button(root, text="Send", command=self.write) + self.send_button.pack(padx=20, pady=5) + + self.stop_button = tk.Button(root, text="Stop", command=self.stop) + self.stop_button.pack(padx=20, pady=5) + + self.root.protocol("WM_DELETE_WINDOW", self.stop) + + self.nickname = simpledialog.askstring("Nickname", "Please choose a nickname", parent=root) + client.send(self.nickname.encode('utf-8')) + + self.running = True + self.receive_thread = threading.Thread(target=self.receive) + self.receive_thread.start() + + def write(self): + message = f"{self.nickname}: {self.msg_entry.get()}" + client.send(message.encode('utf-8')) + self.msg_entry.delete(0, tk.END) + + def receive(self): + while self.running: + try: + message = client.recv(1024).decode('utf-8') + self.text_area.config(state='normal') + self.text_area.insert(tk.END, message + '\n') + self.text_area.config(state='disabled') + self.text_area.yview(tk.END) + except: + print("An error occurred!") + client.close() + break + + def stop(self): + self.running = False + client.close() + self.root.destroy() + +root = tk.Tk() +app = ChatClient(root) +root.mainloop()