From: <Blu...@us...> - 2009-10-11 13:06:16
|
Revision: 300 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=300&view=rev Author: BlueWolf_ Date: 2009-10-11 13:06:07 +0000 (Sun, 11 Oct 2009) Log Message: ----------- Removing the previous code. Beginning with the new program Removed Paths: ------------- trunk/VP/ trunk/VPS/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Blu...@us...> - 2009-10-12 17:24:04
|
Revision: 301 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=301&view=rev Author: BlueWolf_ Date: 2009-10-12 17:23:56 +0000 (Mon, 12 Oct 2009) Log Message: ----------- And hello world! Added Paths: ----------- trunk/client/ trunk/client/COPYING trunk/client/VP.py trunk/client/core/ trunk/server/ trunk/server/COPYING trunk/server/VP.py trunk/server/core/ Added: trunk/client/COPYING =================================================================== --- trunk/client/COPYING (rev 0) +++ trunk/client/COPYING 2009-10-12 17:23:56 UTC (rev 301) @@ -0,0 +1,280 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS Added: trunk/client/VP.py =================================================================== --- trunk/client/VP.py (rev 0) +++ trunk/client/VP.py 2009-10-12 17:23:56 UTC (rev 301) @@ -0,0 +1,18 @@ +#!/usr/bin/env python + +## This file is part of Virtual Playground +## Copyright (c) 2009 Jos Ratsma + Koen Koning + +## This program is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either +## version 2 of the License, or (at your option) any later version. + +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. + +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Added: trunk/server/COPYING =================================================================== --- trunk/server/COPYING (rev 0) +++ trunk/server/COPYING 2009-10-12 17:23:56 UTC (rev 301) @@ -0,0 +1,280 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS Added: trunk/server/VP.py =================================================================== --- trunk/server/VP.py (rev 0) +++ trunk/server/VP.py 2009-10-12 17:23:56 UTC (rev 301) @@ -0,0 +1,18 @@ +#!/usr/bin/env python + +## This file is part of Virtual Playground +## Copyright (c) 2009 Jos Ratsma + Koen Koning + +## This program is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either +## version 2 of the License, or (at your option) any later version. + +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. + +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ch...@us...> - 2009-10-21 22:34:34
|
Revision: 305 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=305&view=rev Author: chozone Date: 2009-10-21 22:34:25 +0000 (Wed, 21 Oct 2009) Log Message: ----------- Begin of both client and server, core and app. -Server core: -Callback system -Accept incoming connections -Send/receive data -Client core: -Callback system -Connect to server -Send/receive data Modified Paths: -------------- trunk/client/VP.py Added Paths: ----------- trunk/client/callback.py trunk/client/core/__init__.py trunk/client/core/callback.py trunk/client/core/client.py trunk/client/core/parser.py trunk/server/VPS.py trunk/server/callback.py trunk/server/core/__init__.py trunk/server/core/callback.py trunk/server/core/parser.py trunk/server/core/server.py Removed Paths: ------------- trunk/server/VP.py Modified: trunk/client/VP.py =================================================================== --- trunk/client/VP.py 2009-10-18 19:17:08 UTC (rev 304) +++ trunk/client/VP.py 2009-10-21 22:34:25 UTC (rev 305) @@ -16,3 +16,22 @@ ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +import time +import core +from callback import Callback + +def main(): + client = core.Client(Callback) + client.connect('localhost', 5162) + + while 1: + #Pygame event loop should go here later. + try: + time.sleep(5000) + except KeyboardInterrupt: + print + exit() + +if __name__ == '__main__': main() + Added: trunk/client/callback.py =================================================================== --- trunk/client/callback.py (rev 0) +++ trunk/client/callback.py 2009-10-21 22:34:25 UTC (rev 305) @@ -0,0 +1,35 @@ +## This file is part of Virtual Playground +## Copyright (c) 2009 Jos Ratsma + Koen Koning + +## This program is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either +## version 2 of the License, or (at your option) any later version. + +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. + +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +import core + +class Callback(core.Callback): + def connected(self, con): + print 'Connected!' + self.con = con + con.send('HI') + + def disconnected(self): + print 'CONNECTION DEAD' + #return True #reconnect + + def data_received(self, data): + print '<', repr(data) + + def data_send(self, data): + print '>', repr(data) + Added: trunk/client/core/__init__.py =================================================================== --- trunk/client/core/__init__.py (rev 0) +++ trunk/client/core/__init__.py 2009-10-21 22:34:25 UTC (rev 305) @@ -0,0 +1,21 @@ +## This file is part of Virtual Playground +## Copyright (c) 2009 Jos Ratsma + Koen Koning + +## This program is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either +## version 2 of the License, or (at your option) any later version. + +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. + +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +import client, callback +Client = client.Client +Callback = callback.Callback + Added: trunk/client/core/callback.py =================================================================== --- trunk/client/core/callback.py (rev 0) +++ trunk/client/core/callback.py 2009-10-21 22:34:25 UTC (rev 305) @@ -0,0 +1,62 @@ +## This file is part of Virtual Playground +## Copyright (c) 2009 Jos Ratsma + Koen Koning + +## This program is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either +## version 2 of the License, or (at your option) any later version. + +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. + +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +class Callback: + def connected(self, con): + """ + connected(self, con) + This will be called when a connection with the server is made. + `con` contains the core's `Client` class, so you can use it to + send stuff. + + This is a placeholder. + If you want to catch this event, overwrite it. + """ + pass + + def disconnected(self): + """ + connected(self) + This is called when the connection dies. For example when you + close the connection manually, the server kicks you, your modem + explodes or your cat eates the LAN cable. + + This is a placeholder. + If you want to catch this event, overwrite it. + """ + pass + + def data_received(self, data): + """ + data_received(self, data) + Called when we received data from the server. + + This is a placeholder. + If you want to catch this event, overwrite it. + """ + pass + + def data_send(self, data): + """ + data_send(self, data) + Called when we send data to the server. + + This is a placeholder. + If you want to catch this event, overwrite it. + """ + pass + Added: trunk/client/core/client.py =================================================================== --- trunk/client/core/client.py (rev 0) +++ trunk/client/core/client.py 2009-10-21 22:34:25 UTC (rev 305) @@ -0,0 +1,156 @@ +## This file is part of Virtual Playground +## Copyright (c) 2009 Jos Ratsma + Koen Koning + +## This program is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either +## version 2 of the License, or (at your option) any later version. + +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. + +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +import simplejson, socket, threading, time +from parser import Parser + + +class Client(threading.Thread): + def __init__(self, callback_class): + """ + This class will handle all of the connection to the server. + """ + + self.__call = callback_class() + self.__sock = None + self.__pinger = None + self.__parse = Parser(self.__call, self) + self.is_online = True + + threading.Thread.__init__(self) + + def connect(self, host, port): + """ + Will (try to) connect to the server on `host`:`port`. + If you want to reconnect, you have to close the connection + first, if it's still open. + """ + + self.__host = host + self.__port = port + + if self.__sock: + raise Exception, "You are already connected!" + + self.__sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + + self.start() + + def run(self): + """ + Used by threading, not for external usage. + """ + + #TODO: reconnect loop thingy here + + while 1: + try: + self.__sock.connect((self.__host, self.__port)) + break + except: + time.sleep(1) + + self.__call.connected(self) + + self.__pinger = self.__Pinger(self.send) + + + #Infinite loop that receives data + buffer = '' + while 1: + try: + data = self.__sock.recv(1024) + except: + if self.is_online: self.close() + return + if not data: + if self.is_online: self.close() + return + + buffer += data + #Each dataset must end with a delimiter: chr(1) + if chr(1) in buffer: + data = buffer.split(chr(1)) + buffer = data[-1] + data = data[:-1] + + for msg in data: + self.__parse(simplejson.loads(msg)) + + def send(self, data_header, data_body = {}): + """ + send(data_header, data_body = {}) => None + Sends `data_body` of type `data_header` to the server. It will + automatically be encoded as JSON, and the delimeter character + (chr(1)) will be send automatically too. + `Data_header` is a string, `data_body` a dict. + """ + try: + self.__call.data_send({data_header:data_body}) + data = simplejson.dumps({data_header:data_body}) + self.__sock.send(data + chr(1)) + except: pass + + + def close(self): + """ + close(self) => None + Will close the connection to the server. If the connection in + already down, it will raise an exception. This will trigger the + callback `disconnected`. It may reconnect, depending on the + callback. If not, you can reuse this class by calling `connect`. + """ + + if not self.is_online: + raise Exception, "The connection is already closed!" + + self.__sock.close() + self.is_online = False + if self.__call.disconnected(): + self.__sock = None + self.connect(self.__host, self.__port) + + class __Pinger(): + def __init__(self, send): + """ + Will ping every 30 seconds for food. If the server + doesn't receive anything from us for 45 sec, it will + drop the connection, because it thinks our computer blew + up or something... + """ + self.running = True + + self.send = send + self.timer = threading.Timer(30, self.run) + self.timer.start() + + def run(self): + if self.running == False: return + + #Ping! + self.send('PNG', {}) + + #Start again + self.timer = threading.Timer(30, self.run) + self.timer.start() + + def cancel(self): + if self.running: + self.timer.cancel() + self.running = False + + Added: trunk/client/core/parser.py =================================================================== --- trunk/client/core/parser.py (rev 0) +++ trunk/client/core/parser.py 2009-10-21 22:34:25 UTC (rev 305) @@ -0,0 +1,33 @@ +## This file is part of Virtual Playground +## Copyright (c) 2009 Jos Ratsma + Koen Koning + +## This program is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either +## version 2 of the License, or (at your option) any later version. + +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. + +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +class Parser(): + def __init__(self, callback, client): + """ + This class parses all received messages from client. + It may need a better name... + """ + self.__call = callback + self.__client = client + + def __call__(self, msg): + self.__call.data_received(msg) + + head = msg.keys()[0] + body = msg[head] + + #handle data here later... Deleted: trunk/server/VP.py =================================================================== --- trunk/server/VP.py 2009-10-18 19:17:08 UTC (rev 304) +++ trunk/server/VP.py 2009-10-21 22:34:25 UTC (rev 305) @@ -1,18 +0,0 @@ -#!/usr/bin/env python - -## This file is part of Virtual Playground -## Copyright (c) 2009 Jos Ratsma + Koen Koning - -## This program is free software; you can redistribute it and/or -## modify it under the terms of the GNU General Public License -## as published by the Free Software Foundation; either -## version 2 of the License, or (at your option) any later version. - -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. - -## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Copied: trunk/server/VPS.py (from rev 304, trunk/server/VP.py) =================================================================== --- trunk/server/VPS.py (rev 0) +++ trunk/server/VPS.py 2009-10-21 22:34:25 UTC (rev 305) @@ -0,0 +1,40 @@ +#!/usr/bin/env python + +## This file is part of Virtual Playground +## Copyright (c) 2009 Jos Ratsma + Koen Koning + +## This program is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either +## version 2 of the License, or (at your option) any later version. + +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. + +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +import time +import core +from callback import Callback + +def main(): + conf = {'host':'', + 'port':5162, + 'max_connections':0} + + server = core.Server(conf, Callback) + server.start_server() + + while 1: + try: + time.sleep(5000) + except KeyboardInterrupt: + print + exit() + +if __name__ == '__main__': main() + Property changes on: trunk/server/VPS.py ___________________________________________________________________ Added: svn:mergeinfo + Added: trunk/server/callback.py =================================================================== --- trunk/server/callback.py (rev 0) +++ trunk/server/callback.py 2009-10-21 22:34:25 UTC (rev 305) @@ -0,0 +1,49 @@ +## This file is part of Virtual Playground +## Copyright (c) 2009 Jos Ratsma + Koen Koning + +## This program is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either +## version 2 of the License, or (at your option) any later version. + +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. + +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +import core + +class Callback(core.Callback): + def server_online(self, clients): + print 'Server is online! :-)' + self.clients = clients + + def connection_opened(self, uid, client, host, port): + print 'New connection:', uid + + def connection_close(self, uid): + print 'Connection dead:', uid + + def connection_limit_exceeded(self, ip, current_connections, + max_connections): + print 'Connection limit exceeded: used %s/%s slots, auto '\ + 'accepted request from %s.' % (current_connections, + max_connections, ip) + return True + + def data_send(self, uid, data): + print '>', repr(data) + + def data_received(self, uid, data): + print '<', repr(data) + + head = data.keys()[0] + body = data[head] + + if head == 'HI': + self.clients[uid].send('LO') + Added: trunk/server/core/__init__.py =================================================================== --- trunk/server/core/__init__.py (rev 0) +++ trunk/server/core/__init__.py 2009-10-21 22:34:25 UTC (rev 305) @@ -0,0 +1,21 @@ +## This file is part of Virtual Playground +## Copyright (c) 2009 Jos Ratsma + Koen Koning + +## This program is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either +## version 2 of the License, or (at your option) any later version. + +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. + +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +import server, callback +Server = server.Server +Callback = callback.Callback + Added: trunk/server/core/callback.py =================================================================== --- trunk/server/core/callback.py (rev 0) +++ trunk/server/core/callback.py 2009-10-21 22:34:25 UTC (rev 305) @@ -0,0 +1,90 @@ +## This file is part of Virtual Playground +## Copyright (c) 2009 Jos Ratsma + Koen Koning + +## This program is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either +## version 2 of the License, or (at your option) any later version. + +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. + +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +class Callback: + def server_online(self, clients): + """ + server_online(self, clients) + Called when the server is online and ready to accept incoming + connections. This means it has successfully bounded itself to a + port. Most of the times this will be called immediately after + calling Server.start() + + This is a placeholder. + If you want to catch this event, overwrite it. + """ + pass + + def connection_opened(self, uid, client, host, port): + """ + connection_opened(self, uid, client, host, port) + Called when a new client connects, and we accepted the + connection. You can, however, still kill the connection by + returning True in this function. + + This is a placeholder. + If you want to catch this event, overwrite it. + """ + pass + + def connection_closed(self, uid): + """ + connection_closed(self, uid) + Called when a connection with a client is closed. This can be + when they closed their connection themselves, or when we + disconnect someone. + + This is a placeholder. + If you want to catch this event, overwrite it. + """ + #TODO: Reason? + pass + + def connection_limit_exceeded(self, ip, current_connections, + max_connections): + """ + connection_limit_exceeded(self, ip, current_connections, + max_connections) + Called when a new client connects, but the maximum number of + connections is exceeded. You can, however, still accept the + connection by returning True in this function. + + This is a placeholder. + If you want to catch this event, overwrite it. + """ + pass + + def data_received(self, uid, data): + """ + data_received(self, uid, data) + Called when the server received data from one of the clients. + + This is a placeholder. + If you want to catch this event, overwrite it. + """ + pass + + def data_send(self, uid, data): + """ + data_send(self, uid, data) + Called when the server send data to one of the clients. + + This is a placeholder. + If you want to catch this event, overwrite it. + """ + pass + Added: trunk/server/core/parser.py =================================================================== --- trunk/server/core/parser.py (rev 0) +++ trunk/server/core/parser.py 2009-10-21 22:34:25 UTC (rev 305) @@ -0,0 +1,35 @@ +## This file is part of Virtual Playground +## Copyright (c) 2009 Jos Ratsma + Koen Koning + +## This program is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either +## version 2 of the License, or (at your option) any later version. + +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. + +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +class Parser(): + def __init__(self, callback, clients): + """ + This class parses all received messages from client. + It may need a better name... + """ + self.__call = callback + self.__clients = clients + + def __call__(self, uid, msg): + self.__call.data_received(uid, msg) + + head = msg.keys()[0] + body = msg[head] + + if head == 'PNG': #Ping + pass #Should this have it's own callback/do anything? + Added: trunk/server/core/server.py =================================================================== --- trunk/server/core/server.py (rev 0) +++ trunk/server/core/server.py 2009-10-21 22:34:25 UTC (rev 305) @@ -0,0 +1,201 @@ +## This file is part of Virtual Playground +## Copyright (c) 2009 Jos Ratsma + Koen Koning + +## This program is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either +## version 2 of the License, or (at your option) any later version. + +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. + +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +import simplejson, socket, threading, time +from parser import Parser + +class Server(threading.Thread): + def __init__(self, config, callback_class): + """ + Will handle all connections from clients. It has one main + socket, and creates all (client)sockets. + + + Config: (maybe this explanation should be moved? maybe provide + example config with the core? maybe this function + should check the given config for error, raise + exceptions, and fill in standard values for some + missing keys) + Should be dict with settings for the server. Below a list of all + posible keys and an explanation. + + -host: Host to which the server binds itself(am i saying this + correctly?) standard value is '', an empty string, which + means everyone can connect to the server. + -port: Port the server should listen on. Should be int, and can + be anything. + -max_connections: Maximum ammount of clients that can be + connected simultaneously. If this number is exceeded, + the client will dropped, unless specified otherwise (see + callback `connection_limit_exceeded`). Should be int. If + this value is either None or 0, there will be no limit. + """ + + self.__sock = None + self.__call = callback_class() + self.__config = config + self.__clients = {} + self.__parse = Parser(self.__call, self.__clients) + + threading.Thread.__init__(self) + + def start_server(self): + """ + start_server() => None + + This will start the server. It will listen on the port + specified in the config. + """ + + #Isn't the server running already? + if self.__sock: + raise Exception, "The server is already online!" + + #Load our server socket + self.__sock = socket.socket(socket.AF_INET, + socket.SOCK_STREAM) + #Configure it to re-use the previous one + self.__sock.setsockopt(socket.SOL_SOCKET, + socket.SO_REUSEADDR, 1) + + self.start() #For more adventures of the socket, see `run` + + + def run(self): + """ + Used by threading, not for external usage. + """ + + #Try to claim the pre-specified port + while 1: + try: + self.__sock.bind((self.__config['host'], + self.__config['port'])) + break + except: + time.sleep(1) + + self.__sock.listen(20) + self.__call.server_online(self.__clients) + + #Infinite loop that will wait for incomming connections + while 1: + sock, addr = self.__sock.accept() + + if self.__config['max_connections'] != None and \ + len(self.__clients) >= \ + self.__config['max_connections']: + #We exceeded our connection limit, but maybe + #this is a special occasion? Send callback! + if not self.__call.connection_limit_exceeded( + addr[0], len(self.__clients), + self.__config['max_connections']): + + #We're full, kick him out + #TODO: Tell him we're full? + sock.close() + continue + + uid = addr[0] + ':' + str(addr[1]) + self.__clients[uid] = Client(uid, sock, self.__clients, + self.__call, self.__parse) + self.__clients[uid].start() + + if self.__call.connection_opened(uid, + self.__clients[uid], *addr): + #User returned True -> drop user + time.sleep(0.1) #Let the `run` start + self.__clients[uid].close() + + + +class Client(threading.Thread): + def __init__(self, uid, sock, clients, callback, parser): + """ + This class manages the socket for the connection to clients. + Each client has it's own class. + """ + + self.__uid = uid + self.__sock = sock + self.__clients = clients + self.__call = callback + self.__parser = parser + self.is_online = True + + threading.Thread.__init__(self) + + def __repr__(self): + return '<Client(%s)>'%self.__uid + + def run(self): + """ + Used by threading, not for external usage. + """ + #Client must ping (at least) every 30 seconds. So we set a + #timeout of 45 seconds. + self.__sock.settimeout(45) + + #Infinite loop that receives data + buffer = '' + while 1: + try: + data = self.__sock.recv(1024) + except: + #Ping timeout? + if self.is_online: self.close() + return + if not data: + if self.is_online: self.close() + return + + buffer += data + #Each dataset must end with a delimiter: chr(1) + if chr(1) in buffer: + data = buffer.split(chr(1)) + buffer = data[-1] + data = data[:-1] + + for msg in data: + self.__parser(self.__uid, + simplejson.loads(msg)) + + def close(self): + """ + close() => None + Closes this connection, and kills the socket. + """ + + self.__sock.close() + self.is_online = False + + self.__call.connection_close(self.__uid) + + del self.__clients[self.__uid] + + def send(self, data_header, data_body = {}): + """ + send(data_header, data_body = {}) => None + Sends `data_body` of type `data_header` to the client. It will + automatically be encoded as JSON, and the delimeter character + (chr(1)) will be send automatically too. + `Data_header` is a string, `data_body` a dict. + """ + self.__call.data_send(self.__uid, {data_header:data_body}) + data = simplejson.dumps({data_header:data_body}) + self.__sock.send(data + chr(1)) + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <blu...@us...> - 2009-12-15 21:01:48
|
Revision: 319 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=319&view=rev Author: bluewolf_ Date: 2009-12-15 21:01:38 +0000 (Tue, 15 Dec 2009) Log Message: ----------- Removed files that weren't part of the project and where not updated anyway Removed Paths: ------------- trunk/client/VP.py trunk/client/callback.py trunk/server/VPS.py trunk/server/callback.py Deleted: trunk/client/VP.py =================================================================== --- trunk/client/VP.py 2009-12-15 20:57:44 UTC (rev 318) +++ trunk/client/VP.py 2009-12-15 21:01:38 UTC (rev 319) @@ -1,37 +0,0 @@ -#!/usr/bin/env python - -## This file is part of Virtual Playground -## Copyright (c) 2009 Jos Ratsma + Koen Koning - -## This program is free software; you can redistribute it and/or -## modify it under the terms of the GNU General Public License -## as published by the Free Software Foundation; either -## version 2 of the License, or (at your option) any later version. - -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. - -## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -import time -import core -from callback import Callback - -def main(): - client = core.Client(Callback) - client.connect('localhost', 5162) - - while 1: - #Pygame event loop should go here later. - try: - time.sleep(5000) - except KeyboardInterrupt: - print - exit() - -if __name__ == '__main__': main() - Deleted: trunk/client/callback.py =================================================================== --- trunk/client/callback.py 2009-12-15 20:57:44 UTC (rev 318) +++ trunk/client/callback.py 2009-12-15 21:01:38 UTC (rev 319) @@ -1,35 +0,0 @@ -## This file is part of Virtual Playground -## Copyright (c) 2009 Jos Ratsma + Koen Koning - -## This program is free software; you can redistribute it and/or -## modify it under the terms of the GNU General Public License -## as published by the Free Software Foundation; either -## version 2 of the License, or (at your option) any later version. - -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. - -## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -import core - -class Callback(core.Callback): - def connected(self, con): - print 'Connected!' - self.con = con - con.send('HI') - - def disconnected(self): - print 'CONNECTION DEAD' - #return True #reconnect - - def data_received(self, data): - print '<', repr(data) - - def data_send(self, data): - print '>', repr(data) - Deleted: trunk/server/VPS.py =================================================================== --- trunk/server/VPS.py 2009-12-15 20:57:44 UTC (rev 318) +++ trunk/server/VPS.py 2009-12-15 21:01:38 UTC (rev 319) @@ -1,40 +0,0 @@ -#!/usr/bin/env python - -## This file is part of Virtual Playground -## Copyright (c) 2009 Jos Ratsma + Koen Koning - -## This program is free software; you can redistribute it and/or -## modify it under the terms of the GNU General Public License -## as published by the Free Software Foundation; either -## version 2 of the License, or (at your option) any later version. - -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. - -## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -import time -import core -from callback import Callback - -def main(): - conf = {'host':'', - 'port':5162, - 'max_connections':0} - - server = core.Server(conf, Callback) - server.start_server() - - while 1: - try: - time.sleep(5000) - except KeyboardInterrupt: - print - exit() - -if __name__ == '__main__': main() - Deleted: trunk/server/callback.py =================================================================== --- trunk/server/callback.py 2009-12-15 20:57:44 UTC (rev 318) +++ trunk/server/callback.py 2009-12-15 21:01:38 UTC (rev 319) @@ -1,49 +0,0 @@ -## This file is part of Virtual Playground -## Copyright (c) 2009 Jos Ratsma + Koen Koning - -## This program is free software; you can redistribute it and/or -## modify it under the terms of the GNU General Public License -## as published by the Free Software Foundation; either -## version 2 of the License, or (at your option) any later version. - -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. - -## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -import core - -class Callback(core.Callback): - def server_online(self, clients): - print 'Server is online! :-)' - self.clients = clients - - def connection_opened(self, uid, client, host, port): - print 'New connection:', uid - - def connection_close(self, uid): - print 'Connection dead:', uid - - def connection_limit_exceeded(self, ip, current_connections, - max_connections): - print 'Connection limit exceeded: used %s/%s slots, auto '\ - 'accepted request from %s.' % (current_connections, - max_connections, ip) - return True - - def data_send(self, uid, data): - print '>', repr(data) - - def data_received(self, uid, data): - print '<', repr(data) - - head = data.keys()[0] - body = data[head] - - if head == 'HI': - self.clients[uid].send('LO') - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ch...@us...> - 2010-07-30 00:07:35
|
Revision: 347 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=347&view=rev Author: chozone Date: 2010-07-30 00:07:29 +0000 (Fri, 30 Jul 2010) Log Message: ----------- [client] * Changed (fake login) user/pass to 'test'/'123' * Now connects with 'localhost' (temp!) [server] * Added base: * Loads config (asks user for values first time) * Opens database connection * Callback checks in database for logins [server-core] * Error corrections in comments * Modified code/comments for conversion to tabs with a width of 4 characters. * The server now uses select for it's main (listening) socket. socket.accept() blocks quite aggressively on Windows, making it impossible to close the server correctly. Using select fixes this. Modified Paths: -------------- trunk/client/VP.py trunk/client/playground.py trunk/server/core/callback.py trunk/server/core/functions.py trunk/server/core/parser.py trunk/server/core/server.py Added Paths: ----------- trunk/server/VPS.py trunk/server/callback.py trunk/server/database.py trunk/server/functions.py Modified: trunk/client/VP.py =================================================================== --- trunk/client/VP.py 2010-07-29 22:04:01 UTC (rev 346) +++ trunk/client/VP.py 2010-07-30 00:07:29 UTC (rev 347) @@ -47,7 +47,7 @@ Callback(self.sh)) self.changestatus("connecting") - self.sh['client'].connect('vp.bluewolf.nl', 6653) + self.sh['client'].connect('localhost', 6653) # Wait for all the events to come Modified: trunk/client/playground.py =================================================================== --- trunk/client/playground.py 2010-07-29 22:04:01 UTC (rev 346) +++ trunk/client/playground.py 2010-07-30 00:07:29 UTC (rev 347) @@ -22,7 +22,7 @@ if ev.type == KEYDOWN and ev.unicode == "\r": # Fake login self.drawlogin("logging in") - self.sh['client'].login("BlueWolf", "mypass") + self.sh['client'].login("test", "123") def changestatus(self, status): Added: trunk/server/VPS.py =================================================================== --- trunk/server/VPS.py (rev 0) +++ trunk/server/VPS.py 2010-07-30 00:07:29 UTC (rev 347) @@ -0,0 +1,40 @@ +#!/usr/bin/env python + +## This file is part of Virtual Playground +## Copyright (c) 2009-2010 Jos Ratsma + Koen Koning + +## This program is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either +## version 2 of the License, or (at your option) any later version. + +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. + +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +import core +from functions import * +from callback import Callback + + +server = core.Server(config, Callback()) +server.start_server() + +# Now we sit back and let the server do it's stuff. Only stop at +# Keyboardinterrupts (^C). +# TODO: *some* interactivity here? (so you can type in commands) +try: + while 1: + time.sleep(100) + +except KeyboardInterrupt: + print + + +server.exit() +sys.exit() Added: trunk/server/callback.py =================================================================== --- trunk/server/callback.py (rev 0) +++ trunk/server/callback.py 2010-07-30 00:07:29 UTC (rev 347) @@ -0,0 +1,48 @@ +## This file is part of Virtual Playground +## Copyright (c) 2009-2010 Jos Ratsma + Koen Koning + +## This program is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either +## version 2 of the License, or (at your option) any later version. + +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. + +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +from core import Callback as BaseCallback + +from functions import * + +class Callback(BaseCallback): + def data_received(self, cid, data): + print " --> " + cid + ": " + repr(data) + def data_send(self, cid, data): + print " <-- " + cid + ": " + repr(data) + def debug_crash(self, traceback): + print "\n*** Crash ***\n\n%s\n" % traceback + + + def server_online(self, clients): + print "*** SERVER ONLINE ***" + + def enters_vp(self, cid): + " > %s"%cid + def enters_vp(self, cid): + " < %s"%cid + + def check_login(self, usr, pwd): + db.execute("SELECT `username` FROM `users` WHERE \ + `username`=%s AND \ + `password`=%s", (usr, pwd)) + print "* Login %s %s" % (usr, pwd) + result = db.fetchone() + if result is None: + return False + else: + return result['username'] \ No newline at end of file Modified: trunk/server/core/callback.py =================================================================== --- trunk/server/core/callback.py 2010-07-29 22:04:01 UTC (rev 346) +++ trunk/server/core/callback.py 2010-07-30 00:07:29 UTC (rev 347) @@ -16,24 +16,31 @@ ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. class Callback: - def server_online(self): + def server_online(self, clients): """ Called when the server is online and ready to accept incoming - connections. This means it has successfully bounded itself to a - port. Most of the times this will be called immediately after - calling Server.start() + connections. This means it has successfully bounded itself to a port. + Most of the times this will be called immediately after calling + Server.start() + clients: + This is a dict where the server will store all the clients. The + server itself stores the socket-class and status of the user here. + However, you can add as much of your own data as you want, as long + as you don't overwrite any existing keys. So you probably want to + save a reference to this dict for easy user management. - This is a placeholder. If you want to catch this event, - overwrite this in your own callback. + + This is a placeholder. If you want to catch this event, overwrite this + in your own callback class. """ pass def connection_opened(self, cid, client, host, port): """ - Called when a new client connects and we accepted the - connection. You can, however, still kill the connection by - returning True in this function. + Called when a new client connects and we accepted the connection. + You can, however, still kill the connection by returning True in this + function. cid: The unique ID for this connection (connection-id). @@ -45,8 +52,8 @@ The current port for this connection. - This is a placeholder. If you want to catch this event, - overwrite this in your own callback. + This is a placeholder. If you want to catch this event, overwrite this + in your own callback class. """ pass @@ -75,8 +82,8 @@ get the precise error - This is a placeholder. If you want to catch this event, - overwrite this in your own callback. + This is a placeholder. If you want to catch this event, overwrite this + in your own callback class. """ pass @@ -90,16 +97,15 @@ current_connections: Amount of current open connections max_connections: - This is the same as in the config - 'max_connections'. + This is the same as in the config 'max_connections'. host: The IP adress for this user. port: The current port for this connection. - This is placeholder. If you want to catch this event, - overwrite this in your own callback. + This is a placeholder. If you want to catch this event, overwrite this + in your own callback class. """ pass @@ -112,8 +118,8 @@ The unique ID for this connection (connection-id) - This is a placeholder. If you want to catch this event, - overwrite this in your own callback. + This is a placeholder. If you want to catch this event, overwrite this + in your own callback class. """ pass @@ -128,57 +134,57 @@ Dict with the data that will be send. - This is a placeholder. If you want to catch this event, - overwrite this in your own callback. + This is a placeholder. If you want to catch this event, overwrite this + in your own callback class. """ pass - def debug_crash(self, tracback): + def debug_crash(self, traceback): """ - Usefull for debugging. Normally, when the parser (our any code - in the parser, like the callback) crashes, the connection will - be kicked and the error will be ignored. If you want to know the - precise error, use this function to get the trackback + Usefull for debugging. Normally, when the parser (or any code in the + parser, like the callback) crashes, the connection will be kicked and + the error will be ignored. If you want to know the precise error, use + this function to get the trackback traceback: A string... with a traceback, duh :-) - This is a placeholder. If you want to catch this event, - overwrite this in your own callback. + This is a placeholder. If you want to catch this event, overwrite this + in your own callback class. """ pass def check_login(self, usr, pwd): """ - This is used to verify the user's login. Return the real - username* when it's correct and False when it's not. This - function will return False by default. + This is used to verify the user's login. Return the real username* when + it's correct and False when it's not. This function will return False + by default. - * This is in case you decide to not make the username case - intensive. Now the clients knows the real username + * This is in case you decide to not make the username case sensetive. + Now the clients knows the real username. usr: The username pwd: The (double) sha-ed password - This is a placeholder. If you want to catch this event, - overwrite this in your own callback. + This is a placeholder. If you want to catch this event, overwrite this + in your own callback class. """ return False def may_login(self, username, screenname, ip, bot, bots): """ - This is called after (a succesfull) callback.check_login. Use - this to block certain users or IP's or block an additional bot - when the users reached the limit of connected bots. + This is called after (a succesfull) callback.check_login. Use this to + block certain users or IP's or block an additional bot when the users + reached the limit of connected bots. - Return True when the user (or bot) may log in and False when it - may not. This will send an "not allowed" error. If you wish to - send an other error, return the error. An example may be: + Return True when the user (or bot) may log in and False when it may not. + This will send an "not allowed" error. If you wish to send an other + error, return the error. An example may be: * "login not allowed" - Login is not allowed right now * "bot limit reached" - User has to much bots running * "login blocked" - User is blocked @@ -188,8 +194,8 @@ username: The username for this user / owner for this bot screenname: - The name the users see. This is only different from - username when a bot logs in + The name the users see. This is only different from username when a + bot logs in ip: The IP-adress this user has bot: @@ -198,8 +204,8 @@ List with the cids of all active active bots for this user. - This is a placeholder. If you want to catch this event, - overwrite this in your own callback. + This is a placeholder. If you want to catch this event, overwrite this + in your own callback class. """ return True @@ -209,7 +215,12 @@ cid: The unique ID for this connection. (connection-id) + + + This is a placeholder. If you want to catch this event, overwrite this + in your own callback class. """ + pass def leaves_vp(self, cid): """ @@ -217,4 +228,9 @@ cid: The unique ID for this connection. (connection-id) + + + This is a placeholder. If you want to catch this event, overwrite this + in your own callback class. """ + pass Modified: trunk/server/core/functions.py =================================================================== --- trunk/server/core/functions.py 2010-07-29 22:04:01 UTC (rev 346) +++ trunk/server/core/functions.py 2010-07-30 00:07:29 UTC (rev 347) @@ -24,20 +24,20 @@ Examples of some expression are: Exact match: - '1.0.3' match ONLY that version (True if version equal given) + '1.0.3' match ONLY that version (True if version equals given) Greater than: - '>0.9.48' match all versions above version '0.9.48', AND '0.9.48' - itself (True if same or above given) + '>0.9.48' match all versions above version '0.9.48', AND '0.9.48' itself + (True if same or above given) Lower than: - '<10.4.0' match all versions below version '10.4.0', AND '10.4.0' - itself (True if same or below given) + '<10.4.0' match all versions below version '10.4.0', AND '10.4.0' itself + (True if same or below given) Range: - '0.9.3-0.9.11' match all versions between '0.9.3' and '0.9.11', - including those values themselves (True if same or - between two values) + '0.9.3-0.9.11' match all versions between '0.9.3' and '0.9.11', including + those values themselves + (True if same or between two values) If all conditions are met, this function will return True, otherwise @@ -49,25 +49,25 @@ This is because it's not a decimal number. """ - # Filter out invalid versions/expressions, so this function works - # correctly later on. + # Filter out invalid versions/expressions, so this function works correctly + # later on. if not expr: return True if not version: return False version = str(version) expr = str(expr) try: [int(i) for i in version.split('.')] - except ValueError: raise ValueError, "No valid version: '%s'"%version + except ValueError: raise ValueError("No valid version: '%s'"%version) try: [[int(i) for i in p.split('.')] \ for p in expr.strip('<>').split('-')] - except ValueError: raise ValueError, "No valid expression: '%s'"%expr + except ValueError: raise ValueError("No valid expression: '%s'"%expr) # Our first real tests. If version matches expression, we return True. # Also, if the expression, stripped of '<' and '>' characters at the # beginning (or end...) matched our version, we return True. - # This is for the 'Greater/Lower OR EQUAL than' behaviour of those + # This is for the 'Greater/Lower OR EQUAL than' behaviour of those # characters. if version == expr: return True if version == expr.strip('<>'): return True @@ -83,10 +83,9 @@ c1 = [int(i) for i in version.split('.')] c2 = [int(i) for i in expr.split('.')] - # Loops through major, minor, revision, in that order, and - # it tests whether the version is higher/lower. Note that if the - # version are the same, it has already been filtered out, before - # this if block. + # Loops through major, minor, revision, in that order, and it tests + # whether the version is higher/lower. Note that if the version are the + # same, it has already been filtered out, before this if block. for p1, p2 in zip(c1, c2): if p1 > p2: return True if p1 < p2: return False @@ -103,10 +102,9 @@ c1 = [int(i) for i in version.split('.')] c2 = [int(i) for i in expr.split('.')] - # Loops through major, minor, revision, in that order, and - # it tests whether the version is higher/lower. Note that if the - # version are the same, it has already been filtered out, before - # this if block. + # Loops through major, minor, revision, in that order, and it tests + # whether the version is higher/lower. Note that if the version are the + # same, it has already been filtered out, before this if block. for p1, p2 in zip(c1, c2): if p1 < p2: return True if p1 > p2: return False @@ -116,8 +114,8 @@ # Get the two versions r1, r2 = expr.split('-') - # Use this function to see if it's higher than the first, and - # lower than the second value :-) + # Use this function to see if it's higher than the first, and lower + # than the second value :-) if check_version(version, '>' + r1) \ and check_version(version, '<' + r2): return True Modified: trunk/server/core/parser.py =================================================================== --- trunk/server/core/parser.py 2010-07-29 22:04:01 UTC (rev 346) +++ trunk/server/core/parser.py 2010-07-30 00:07:29 UTC (rev 347) @@ -163,13 +163,11 @@ # Check for double logins if msg['bot'] == False: # Just an ordinary user - if self._check_double_user(False, username, - data) == False: + if self._check_double_user(False, username, data) == False: return else: # Client is a bot - if self._check_double_user(True, screenname, - data) == False: + if self._check_double_user(True, screenname, data) == False: return Modified: trunk/server/core/server.py =================================================================== --- trunk/server/core/server.py 2010-07-29 22:04:01 UTC (rev 346) +++ trunk/server/core/server.py 2010-07-30 00:07:29 UTC (rev 347) @@ -15,7 +15,7 @@ ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -import simplejson, socket, threading, time, random, sys, hashlib +import simplejson, socket, threading, time, random, sys, hashlib, select from functions import * from parser import Parser @@ -30,9 +30,8 @@ config: - This should be a dict with settings for the server. See the - bottom of this documentation for a list of all possible - settings. + This should be a dict with settings for the server. See the bottom of + this documentation for a list of all possible settings. callback_class: The callback class will be used to notify you for certain events @@ -47,22 +46,21 @@ The settings: -host: - Host to which the server binds itself. The default is an - empty string, an empty string, which means everyone can - connect to the server. + Host to which the server binds itself. The default is an empty + string, an empty string, which means everyone can connect + to the server. -port: - The port the server should listen on. Should be int - between 1 and 65535. Note that everything lower than 100 - usually needs to be run as root under Unix/Linux. + The port the server should listen on. Should be int between + 1 and 65535. Note that everything lower than 100 usually needs to + be run as root under Unix/Linux. Default is 5162. -max_connections: - Maximum amount of clients that can be connected - simultaneously. If this number is exceeded, the new - connection will dropped, unless specified otherwise - (see callback `connection_limit_exceeded`). Should be - int. If this value is either None or 0, there will be no + Maximum amount of clients that can be connected simultaneously. + If this number is exceeded, the new connection will dropped, unless + specified otherwise (see callback `connection_limit_exceeded`). + Should be int. If this value is either None or 0, there will be no limit. Default is 0. But it is wise to specify a limit. -rsa_bits: @@ -70,23 +68,21 @@ More = more secure but slower to generate. Default is 64 -bot_names: - How the name for a bot should be. Use %s where the - suggested name should be. Default is [%s]. When a bot - logs in as "test", it will be displayed as "[test]". - Choose something that won't interfere with existing - users. + How the name for a bot should be. Use %s where the suggested name + should be. Default is [%s]. When a bot logs in as "test", it will + be displayed as "[test]". Choose something that won't interfere + with existing users. -viewport: - A tuple of the client's viewport in pixels. This is very - important because it's used to calculate which objects - and people the client is able to see. By default this - is (1000, 700). + A tuple of the client's viewport in pixels. This is very important + because it's used to calculate which objects and people the client + is able to see. By default this is (1000, 700). -max_speed: The amount of pixels a user may move in a certain time. - The default is (50, 1.0) which basically means 50px per - 1 second. When a user exceeds this, the server will just - reset his position to his last known location. + The default is (50, 1.0) which basically means 50px per 1 second. + When a user exceeds this, the server will just reset his position + to his last known location. """ @@ -130,16 +126,14 @@ in the config. """ - #Isn't the server running already? + # Isn't the server running already? if self.__sock: raise ConnectionError("The server is already online!") - #Load our server socket - self.__sock = socket.socket(socket.AF_INET, - socket.SOCK_STREAM) - #Configure it to re-use the previous one - self.__sock.setsockopt(socket.SOL_SOCKET, - socket.SO_REUSEADDR, 1) + # Load our server socket + self.__sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + # Configure it to re-use the previous one + self.__sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.start() #For more adventures of the socket, see `run` @@ -149,11 +143,11 @@ Used by threading, not for external usage. """ - #Try to claim the pre-specified port + # Try to claim the pre-specified port while 1: try: self.__sock.bind((self.__sh['config']['host'], - self.__sh['config']['port'])) + self.__sh['config']['port'])) break except: time.sleep(1) @@ -161,25 +155,31 @@ self.__sock.listen(20) self.__call.server_online(self.clients) - #Infinite loop that will wait for incomming connections - while 1: - try: sock, addr = self.__sock.accept() - except: + # Infinite loop that will wait for incomming connections + while 1: + r,w,e = select.select([self.__sock], [], [], 10) + + if not r: + # No new clients trying to connect, better luck next time + continue + if not self.__sock: # Server has gone offline return + sock, addr = r[0].accept() + + if self.__sh['config']['max_connections'] and \ - len(self.clients) >= \ - self.__sh['config']['max_connections']: - #We exceeded our connection limit, but maybe - #this is a special occasion? Send callback! + len(self.clients) >= self.__sh['config']['max_connections']: + # We exceeded our connection limit, but maybe this is a special + # occasion? Send callback! if not self.__call.connection_limit_exceeded( - len(self.clients), - self.__sh['config']['max_connections'], - addr[0], addr[1]): + len(self.clients), + self.__sh['config']['max_connections'], + addr[0], addr[1]): - #We're full, kick him out - #Tell him we're full + # We're full, kick him out + # Tell him we're full data = simplejson.dumps({ "disconnect":{"reason":"full"} }) @@ -192,18 +192,16 @@ # Create unique client-id cid = hashlib.sha1(addr[0] + str(addr[1])).hexdigest()[:8] while cid in self.clients: - cid = hashlib.sha1(addr[0] + str(addr[1]) + - str(random.random())).hexdigest()[:8] + cid = hashlib.sha1(addr[0] + str(addr[1]) + + str(random.random())).hexdigest()[:8] self.clients[cid] = { "status": "", - "con": Client(cid, sock, self.__sh, - self.__parse) + "con": Client(cid, sock, self.__sh, self.__parse) } - if self.__call.connection_opened(cid, - self.clients[cid], *addr): - #User returned True -> drop user + if self.__call.connection_opened(cid, self.clients[cid], *addr): + # User returned True -> drop user self.clients[cid]['con'].close() continue @@ -211,9 +209,9 @@ def exit(self, reason = "gone offline"): """ - Will shutdown the server and sends an 'gone offline' message to - all connected clients and then closes their connection. Use this - when you're about to shutdown your server. + Will shutdown the server and sends an 'gone offline' message to all + connected clients and then closes their connection. Use this when + you're about to shutdown your server. This will call the callback.connection_closed for all clients! Note that you'll not be able to start the server again @@ -225,6 +223,7 @@ for client in self.clients.values(): client['con'].close_msg(reason) + @@ -255,13 +254,12 @@ Will create a traceback and call the callback """ - #Get some debugging info + # Get some debugging info et, ev, tb = sys.exc_info() traceback = "" while tb: co = tb.tb_frame.f_code - traceback += str(co.co_filename) + ':' + \ - str(tb.tb_lineno) + '\n' + traceback += str(co.co_filename) + ':' + str(tb.tb_lineno) + '\n' tb = tb.tb_next traceback += ev.__class__.__name__ + ': ' + str(ev) @@ -294,19 +292,18 @@ Used by threading, not for external usage. """ - #Client must ping (at least) every 30 seconds. So we set a - #timeout of 45 seconds. + # Client must ping (at least) every 30 seconds. So we set a + # timeout of 45 seconds. self.__sock.settimeout(45) - # Before the client can log in, we first need to create a - # rsa-key + # Before the client can log in, we first need to create a rsa-key public, private = rsa.gen_pubpriv_keys( self.__sh['config']['rsa_bits']) self.__clients[self.__cid]['rsa'] = private self.send("rsa", {"public": public}) - #Infinite loop that receives data + # Infinite loop that receives data buffer = '' while 1: try: @@ -322,7 +319,7 @@ return buffer += data - #Each dataset must end with a delimiter: chr(1) + # Each dataset must end with a delimiter: chr(1) if chr(1) in buffer: data = buffer.split(chr(1)) buffer = data[-1] @@ -330,8 +327,7 @@ for msg in data: try: - self.__parser(self.__cid, - simplejson.loads(msg)) + self.__parser(self.__cid, simplejson.loads(msg)) except Exception, Er: self.__parser_crash() @@ -362,8 +358,8 @@ def close_msg(self, reason): """ - Same as Client.close, but this will send the reason to the - client before closing + Same as Client.close, but this will send the reason to the client + before closing. """ if self.is_online == False: return @@ -385,8 +381,8 @@ def send(self, data_header, data_body = {}): """ Sends `data_body` of type `data_header` to the client. It will - automatically be encoded as JSON, and the delimeter character - (chr(1)) will be send automatically too. + automatically be encoded as JSON, and the delimeter character (chr(1)) + will be send automatically too. `data_header` is a string, `data_body` a dict. """ self.__call.data_send(self.__cid, {data_header:data_body}) Added: trunk/server/database.py =================================================================== --- trunk/server/database.py (rev 0) +++ trunk/server/database.py 2010-07-30 00:07:29 UTC (rev 347) @@ -0,0 +1,83 @@ +## Copyright (c) 2009 Koen Koning + Thomas van Ophem + +## This program is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either +## version 2 of the License, or (at your option) any later version. + +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. + +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +import sys + +try: import MySQLdb +except: sys.exit("ERROR: You need the MySQLdb-module for this to work!") + +class DB(): + #Let's initialize the database + def __init__(self, host, database, user, passwd): + self.host = host + self.database = database + self.user = user + self.passwd = passwd + + self._connect() + + #Let's connect to the database.. + def _connect(self): + try: + self.dbcon = MySQLdb.Connect( + host=self.host, + user=self.user, + passwd=self.passwd, + db = self.database) + self.db = self.dbcon.cursor(MySQLdb.cursors.DictCursor) + except: + #sys.exit("Could not connect to the database!") + raise self.DBConnectionError("Could not connect to the database!") + + def __getattr__(self, attr): + """ + Called when function is not here in our class. + We pass everything through to our MySQLdb + """ + def exc (*arg): + """ + Will return the real function, from MySQLdb. + Will ping before every command, + so it will automatically reconnect. + """ + + # Uncomment for mysql-debugging! + #print '\tMySQLdb.' + attr + repr(arg) + + func = getattr(self.db, attr) + try: + dbfunc = func(*arg) + except MySQLdb.OperationalError, message: + if message[0] == 2006: #Mysql has gone away + self._connect() + func = getattr(self.db, attr) + dbfunc = func(*arg) + else: #Some other error we don't care about + raise MySQLdb.OperationalError, message + + return dbfunc + + return exc + + + + class DBConnectionError(Exception): + def __init__(self, value): + self.value = value + def __str__(self): + return repr(self.value) + Added: trunk/server/functions.py =================================================================== --- trunk/server/functions.py (rev 0) +++ trunk/server/functions.py 2010-07-30 00:07:29 UTC (rev 347) @@ -0,0 +1,71 @@ +## This file is part of Virtual Playground +## Copyright (c) 2009-2010 Jos Ratsma + Koen Koning + +## This program is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either +## version 2 of the License, or (at your option) any later version. + +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. + +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +import os, sys, time + +import database + +try: from configobj import ConfigObj +except: sys.exit("ERROR: You need the configobj-module for this to work!") + +def config_defaults(config): + if 'database' not in config: + config['database'] = {} + + intro_text = """ +Some settings are missing from the config. Because these settings are required, +We will now ask for them in this console. Please type in the correct value, and +press enter. It will be automatically written to the config. +""" + + if not 'host' in config['database']: + if intro_text: + print intro_text + intro_text = None + config['database']['host'] = raw_input("Database host: ") + if not 'database' in config['database']: + if intro_text: + print intro_text + intro_text = None + config['database']['database'] = raw_input("Database name: ") + if not 'user' in config['database']: + if intro_text: + print intro_text + intro_text = None + config['database']['user'] = raw_input("Database user: ") + if not 'password' in config['database']: + if intro_text: + print intro_text + intro_text = None + config['database']['password'] = raw_input("Database password: ") + + + +config = ConfigObj(os.path.join(sys.path[0], 'config')) +config_defaults(config) +config.write() + +print "Connecting to database..." +db = database.DB( config['database']['host'], + config['database']['database'], + config['database']['user'], + config['database']['password']) +print "Connected to database `%s` on `%s`" % (config['database']['database'], + config['database']['host']) + + + \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |